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

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

Introduction

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

Prototype

public Collection getOptions() 

Source Link

Usage

From source file:com.ericsson.eiffel.remrem.generate.cli.CLIOptions.java

public static void checkRequiredOptions() throws MissingOptionException {
    OptionGroup[] groups = { typeGroup, contentGroup };
    for (OptionGroup group : groups) {
        ArrayList<Option> groupOptions = new ArrayList<Option>(group.getOptions());
        boolean groupIsGiven = false;
        for (Option option : groupOptions) {
            if (commandLine.hasOption(option.getOpt())) {
                groupIsGiven = true;/*from  w w w.  j  a v a 2  s .  c om*/
                break;
            }
        }
        if (!groupIsGiven) {
            throw new MissingOptionException(groupOptions);
        }
    }
}

From source file:com.ericsson.eiffel.remrem.publish.cli.CliOptions.java

public static void checkRequiredOptions() throws MissingOptionException {
    OptionGroup[] groups = { contentGroup };
    for (OptionGroup group : groups) {
        ArrayList<Option> groupOptions = new ArrayList<Option>(group.getOptions());
        boolean groupIsGiven = false;
        for (Option option : groupOptions) {
            if (commandLine.hasOption(option.getOpt())) {
                groupIsGiven = true;/*from w ww. ja v  a  2s .co  m*/
                break;
            }
        }
        if (!groupIsGiven) {
            throw new MissingOptionException(groupOptions);
        }
    }
}

From source file:bdsup2sub.cli.CommandLineOptionsTest.java

@Test
public void shouldHaveFramerateOptionGroup() {
    OptionGroup optionGroup = options.getOptionGroup(options.getOption("T"));
    assertNotNull(optionGroup);/*from   w ww .  ja  v a2s . c  om*/
    assertTrue(optionGroup.getOptions().contains(options.getOption("T")));
    assertTrue(optionGroup.getOptions().contains(options.getOption("C")));
}

From source file:bdsup2sub.cli.CommandLineOptionsTest.java

@Test
public void shouldHaveMoveOptionGroup() {
    OptionGroup optionGroup = options.getOptionGroup(options.getOption("I"));
    assertNotNull(optionGroup);//from www. ja  va 2  s  .  c  om
    assertTrue(optionGroup.getOptions().contains(options.getOption("I")));
    assertTrue(optionGroup.getOptions().contains(options.getOption("O")));
}

From source file:de.uni_koblenz.ist.utilities.option_handler.OptionHandler.java

private boolean containsAllRequiredOptionGroups(Option[] setOptions) {
    boolean allContained = true;
    for (OptionGroup currentRequiredOptionGroup : requiredOptionGroups) {
        boolean currentContained = false;
        for (Option currentOption : setOptions) {
            currentContained |= currentRequiredOptionGroup.getOptions().contains(currentOption);
            if (currentContained) {
                break;
            }// w  w w  .  ja  v a  2  s . c  om
        }
        allContained &= currentContained;
        if (!allContained) {
            break;
        }
    }
    return allContained;
}

From source file:org.apache.openmeetings.cli.OmHelpFormatter.java

@SuppressWarnings("unchecked")
private static List<OmOption> getReqOptions(Options opts) {
    //suppose we have only 1 group (for now)
    OptionGroup g = ((List<OptionGroup>) opts.getRequiredOptions()).get(0);
    List<OmOption> result = new ArrayList<OmOption>();
    for (Option o : g.getOptions()) {
        result.add((OmOption) o);/*from  ww  w . ja  v  a  2s. c om*/
    }
    Collections.sort(result, new Comparator<OmOption>() {
        @Override
        public int compare(OmOption o1, OmOption o2) {
            return o1.getOrder() - o2.getOrder();
        }
    });
    return result;
}

From source file:org.lockss.devtools.RunKbartReport.java

/**
 * Add the given OptionGroup to the options order list as well as the 
 * options spec.//from w w w.ja v  a 2 s . co m
 * @param g an OptionGroup
 * @param setReq whether to set the option as a required one
 */
private static void addOptionGroup(OptionGroup g, boolean setReq) {
    g.setRequired(setReq);
    for (Object opt : g.getOptions()) {
        optionList.add((Option) opt);
    }
    options.addOptionGroup(g);
}

From source file:org.lockss.devtools.RunKbartReport.java

/**
 * Add the given OptionGroup to the options spec, and its component Options
 * to the options order list. An OptionGroup contains mutually exclusive
 * Options. The selected/default option is set to the first in the list by
 * default./*from  w  w  w  .  ja  v  a 2 s  . com*/
 * @param og an OptionGroup
 */
private static void addOptionGroup(OptionGroup og) {
    for (Object o : og.getOptions())
        optionList.add((Option) o);
    options.addOptionGroup(og);
}

From source file:org.openmeetings.cli.OmHelpFormatter.java

@SuppressWarnings("unchecked")
private List<OmOption> getReqOptions(Options opts) {
    //suppose we have only 1 group (for now)
    OptionGroup g = ((List<OptionGroup>) opts.getRequiredOptions()).get(0);
    List<OmOption> result = new ArrayList<OmOption>(g.getOptions());
    Collections.sort(result, new Comparator<OmOption>() {
        public int compare(OmOption o1, OmOption o2) {
            return o1.getOrder() - o2.getOrder();
        }/*from w w  w  .  j  av  a2  s .  co  m*/
    });
    return result;
}

From source file:org.shaf.core.process.cmd.CommandLineHandler.java

/**
 * Returns a {@link Process process} settings containing 'key/value' pairs,
 * where 'key' - name of the process class filed and 'value' - value to
 * which this field need to be set./*from www  .j  a  v  a  2  s .  c  om*/
 * 
 * @param descr
 *            the process descriptor.
 * @param args
 *            the process arguments.
 * @return the process execution settings.
 * @throws ParseException
 *             if parsing of the command line has failed.
 */
public final static Properties getSettings(final DescriptionContent descr, final String[] args)
        throws ParseException {

    LOG.trace(Strings.repeat("=", 80));
    LOG.trace("| Block for converting the description content and arguments into");
    LOG.trace("| the settings object.");
    LOG.trace("| Content:   " + descr);
    LOG.trace("| Arguments: " + StringUtils.array2string(args));

    /*
     * Converts the process description into the command line options.
     */
    Options options = CommandOptionHandler.getOptions(descr);

    /*
     * Uses the obtained process options to parse command line arguments.
     */
    CommandLine line = new BasicParser().parse(options, args);

    /*
     * Creates process settings object.
     */
    Properties settings = new Properties();
    for (Object elm : options.getOptions()) {

        LOG.trace(Strings.repeat("-", 80));

        /*
         * Converts a single Option or OptionGroup into array of options.
         * Obviously is we converting a single option array will contain
         * only one element.
         */
        Option[] group = new Option[0];
        if (elm instanceof Option) {
            Option o = (Option) elm;
            group = ObjectArrays.concat(group, o);
        } else {
            OptionGroup og = (OptionGroup) elm;
            for (Object e : og.getOptions()) {
                Option o = (Option) e;
                group = ObjectArrays.concat(group, o);
            }
        }

        /*
         * Populates the process execution settings.
         */
        for (Option option : group) {
            LOG.trace("| Select option:   " + option);

            ResourceInfo resInfo = descr.getResourceInfo(option.getOpt());
            SingleOptionInfo optInfo = (SingleOptionInfo) resInfo.getOptionInfo();
            FieldInfo fldInfo = resInfo.getFieldInfo();

            LOG.trace("| Select resource: " + resInfo);

            String fldName = null;
            String fldValue = null;
            if (fldInfo == null) {
                fldName = optInfo.getName();
                if (!Strings.isNullOrEmpty(optInfo.getValue())) {
                    fldValue = line.getOptionValue(optInfo.getName(), optInfo.getValue());
                } else {
                    fldValue = line.getOptionValue(optInfo.getName());
                }
            } else {
                fldName = fldInfo.getName();
                if (boolean.class.getCanonicalName().equals(fldInfo.getType())
                        || Boolean.class.getCanonicalName().equals(fldInfo.getType())) {
                    fldValue = String.valueOf(line.hasOption(optInfo.getName()));
                } else {
                    if (!Strings.isNullOrEmpty(optInfo.getValue())) {
                        fldValue = line.getOptionValue(optInfo.getName(), optInfo.getValue());
                    } else {
                        fldValue = line.getOptionValue(optInfo.getName());
                    }
                }
            }

            if (fldValue != null) {
                settings.put(fldName + ".option", optInfo.getName());
                LOG.trace("| Set: " + fldName + ".option=" + optInfo.getName());

                settings.put(fldName + ".value", fldValue);
                LOG.trace("| Set: " + fldName + ".value=" + fldValue);
            }
        }
    }

    LOG.trace(Strings.repeat("=", 80));

    LOG.debug("Initialized the process settings: " + settings);

    return settings;
}