Example usage for org.apache.commons.cli OptionGroup getNames

List of usage examples for org.apache.commons.cli OptionGroup getNames

Introduction

In this page you can find the example usage for org.apache.commons.cli OptionGroup getNames.

Prototype

public Collection getNames() 

Source Link

Usage

From source file:com.somerledsolutions.pa11y.client.cli.OptionsBuilderTest.java

@Test
public void testBuildPa11yOptions() throws Exception {
    Options options = OptionsBuilder.buildPa11yOptions();

    assertEquals(10, options.getOptions().size());

    assertPa11yOptions(options);//from   w w w. java 2 s.c  om

    OptionGroup optionGroup = options.getOptionGroup(options.getOption("c"));
    Collection<String> optionGroupNames = optionGroup.getNames();
    assertTrue(optionGroupNames.contains("c"));
    assertTrue(optionGroupNames.contains("l"));
    assertTrue(optionGroupNames.contains("r"));
    assertTrue(optionGroupNames.contains("g"));
    assertTrue(optionGroupNames.contains("d"));
}

From source file:org.apache.geronimo.cli.PrintHelper.java

public void printUsage(PrintWriter pw, int width, String app, Options options) {
    // create a list for processed option groups
    ArrayList list = new ArrayList();

    StringBuilder optionsBuff = new StringBuilder();

    // temp variable
    Option option;/*from w  ww  .  j ava  2s  .c  o  m*/

    // iterate over the options
    for (Iterator i = options.getOptions().iterator(); i.hasNext();) {
        // get the next Option
        option = (Option) i.next();

        // check if the option is part of an OptionGroup
        OptionGroup group = options.getOptionGroup(option);

        // if the option is part of a group and the group has not already
        // been processed
        if (group != null && !list.contains(group)) {

            // add the group to the processed list
            list.add(group);

            // get the names of the options from the OptionGroup
            Collection names = group.getNames();

            optionsBuff.append("[");

            // for each option in the OptionGroup
            for (Iterator iter = names.iterator(); iter.hasNext();) {
                optionsBuff.append(iter.next());
                if (iter.hasNext()) {
                    optionsBuff.append("|");
                }
            }
            optionsBuff.append("] ");
        } else if (group == null) {
            // if the Option is not part of an OptionGroup
            // if the Option is not a required option
            if (!option.isRequired()) {
                optionsBuff.append("[");
            }

            if (!" ".equals(option.getOpt())) {
                optionsBuff.append("-").append(option.getOpt());
            } else {
                optionsBuff.append("--").append(option.getLongOpt());
            }

            if (option.hasArg()) {
                optionsBuff.append(" ");
            }

            // if the Option has a value
            if (option.hasArg()) {
                optionsBuff.append(option.getArgName());
            }

            // if the Option is not a required option
            if (!option.isRequired()) {
                optionsBuff.append("]");
            }
            optionsBuff.append(" ");
        }
    }

    app = app.replace("$options", optionsBuff.toString());

    // call printWrapped
    printWrapped(pw, width, app.indexOf(' ') + 1, app);
}