Example usage for org.apache.commons.cli Option setDescription

List of usage examples for org.apache.commons.cli Option setDescription

Introduction

In this page you can find the example usage for org.apache.commons.cli Option setDescription.

Prototype

public void setDescription(String description) 

Source Link

Document

Sets the self-documenting description of this Option

Usage

From source file:com.github.dakusui.symfonion.CLI.java

private Options buildOptions() {
    // create Options object
    Options options = new Options();

    //////from   w  w  w.ja  va2 s . c  o  m
    // Behavior options
    options.addOption("V", "version", false, "print the version information.");
    options.addOption("h", "help", false, "print the command line usage.");
    options.addOption("l", "list", false, "list the available midi devices.");
    options.addOption("p", "play", true, "play the specifiled file.");
    options.addOption("c", "compile", true, "compile the specified file to a standard midi file.");
    {
        Option option = OptionBuilder.create("r");
        option.setLongOpt("route");
        option.setValueSeparator('=');
        option.setArgs(2);
        option.setDescription("run a midi patch bay.");
        options.addOption(option);
    }

    ////
    // I/O options
    {
        Option option = OptionBuilder.create("O");
        option.setValueSeparator('=');
        option.setArgs(2);
        option.setDescription("specify midi out port.");
        options.addOption(option);
    }
    {
        Option option = OptionBuilder.create("I");
        option.setValueSeparator('=');
        option.setArgs(2);
        option.setDescription("specify midi in port.");
        options.addOption(option);
    }
    {
        Option option = OptionBuilder.create("o");
        option.setArgs(1);
        option.setDescription("specify a file to which a compiled standard midi file is output.");
        options.addOption(option);
    }
    return options;
}

From source file:org.apache.accumulo.core.util.shell.commands.MergeCommand.java

@Override
public Options getOptions() {
    final Options o = new Options();
    verboseOpt = new Option("v", "verbose", false, "verbose output during merge");
    sizeOpt = new Option("s", "size", true, "merge tablets to the given size over the entire table");
    forceOpt = new Option("f", "force", false,
            "merge small tablets to large tablets, even if it goes over the given size");
    allOpt = new Option("", "all", false,
            "allow an entire table to be merged into one tablet without prompting the user for confirmation");
    Option startRowOpt = OptUtil.startRowOpt();
    startRowOpt.setDescription("begin row (NOT inclusive)");
    o.addOption(startRowOpt);//from  w  ww  .  j av a 2  s .c o m
    o.addOption(OptUtil.endRowOpt());
    o.addOption(OptUtil.tableOpt("table to be merged"));
    o.addOption(verboseOpt);
    o.addOption(sizeOpt);
    o.addOption(forceOpt);
    o.addOption(allOpt);
    return o;
}

From source file:org.apache.blur.shell.ExecutePlatformCommandCommand.java

private void addOptions(boolean required, Options options, Set<Entry<String, ArgumentDescriptor>> entrySet) {
    for (Entry<String, ArgumentDescriptor> e : entrySet) {
        String argumentName = e.getKey();
        ArgumentDescriptor argumentDescriptor = e.getValue();
        Option option = OptionBuilder.create(argumentName);
        option.setRequired(required);/* w  ww.ja va  2  s  .c  o m*/
        String description = argumentDescriptor.getDescription();
        option.setDescription(createDescription(description, required));
        option.setArgs(1);
        options.addOption(option);
    }
}

From source file:org.codeseed.common.config.ext.CommandLineOptionsBuilder.java

/**
 * Potentially adds an option to the supplied collection. Used by the
 * {@link #build()} method to populate an options collection.
 *
 * @param options//from  w  w w .j av a  2s  .  co  m
 *            the current collection of options
 * @param groups
 *            mappings of argument group identifiers to groups
 * @param method
 *            the configuration method to look up
 */
protected void addOption(Options options, Map<String, OptionGroup> groups, Method method) {
    final CommandLine commandLine = method.getAnnotation(CommandLine.class);

    // Iterate over the triggers; take the first values
    String opt = null;
    String longOpt = null;
    for (String trigger : commandLine.value()) {
        if (!options.hasOption(trigger)) {
            if (opt == null && trigger.length() == 1) {
                opt = trigger;
            } else if (longOpt == null) {
                longOpt = trigger;
            }
        }
    }

    // Either we can use the method name or there is no option being added
    if (opt == null && longOpt == null) {
        String methodOpt = LOWER_CAMEL.to(LOWER_HYPHEN, method.getName());
        if (!options.hasOption(methodOpt)) {
            longOpt = methodOpt;
        } else {
            // TODO Warn?
            return;
        }
    }

    // Create a new option
    Option option = new Option(opt, null);
    option.setLongOpt(longOpt);

    // Set the number of arguments based on the return type
    final Class<?> returnType = Primitives.wrap(method.getReturnType());
    if (returnType.equals(Boolean.class)) {
        option.setArgs(0);
    } else if (Iterable.class.isAssignableFrom(returnType)) {
        option.setArgs(commandLine.maximum());
    } else if (Map.class.isAssignableFrom(returnType)) {
        option.setArgs(2);
        option.setValueSeparator('=');
    } else {
        option.setArgs(1);
    }

    // Add some descriptive text
    if (bundle != null) {
        try {
            // TODO Does this make sense?
            String key = option.hasLongOpt() ? option.getLongOpt() : method.getName();
            option.setDescription(bundle.getString(key + ".description"));
        } catch (MissingResourceException e) {
            option.setDescription(null);
        }
    }

    // Set argument names
    if (bundle != null && option.getArgs() > 0) {
        try {
            option.setArgName(bundle.getString(method.getName() + ".argName"));
        } catch (MissingResourceException e) {
            option.setArgName(null);
        }
    }

    // Add to either the collection or to the option groups
    String groupKey = commandLine.groupId();
    if (groupKey.isEmpty()) {
        options.addOption(option);
    } else {
        OptionGroup group = groups.get(groupKey);
        if (group == null) {
            group = new OptionGroup();
            groups.put(groupKey, group);
        }
        group.addOption(option);
    }
}

From source file:org.deegree.tools.rendering.dem.builder.DEMDatasetGenerator.java

private static Options initOptions() {

    Options opts = new Options();

    RasterOptionsParser.addRasterIOLineOptions(opts);

    Option opt = new Option("o", OPT_OUTPUT_DIR, true, "output directory");
    opt.setRequired(true);//  w ww.  j av  a2  s  .  co m
    opts.addOption(opt);

    opt = new Option("ol", OPT_OUTPUT_LEVELS, true,
            "number of resolution levels in the generated multiresolution model.");
    opts.addOption(opt);

    opt = new Option("or", OPT_OUTPUT_ROWS, true, "number of rows per macrotriangle");
    opt.setDescription("32|64|128");
    opts.addOption(opt);

    opt = new Option("mh", OPT_MAX_HEIGHT, true,
            "maximum z-value, every higher value is clipped to no data value");
    opts.addOption(opt);

    CommandUtils.addDefaultOptions(opts);

    return opts;
}

From source file:org.eclipse.jubula.app.autagent.AutAgentApplication.java

/**
 * method to create an options object, filled with all options
 *
 * @return the options/* w w  w. j  a v a 2  s  .c  o m*/
 */
private static Options createOptions() {
    Options options = new Options();

    Option portOption = new Option(COMMANDLINE_OPTION_PORT, true, Messages.CommandlineOptionPort);
    portOption.setArgName(COMMANDLINE_PORT);
    options.addOption(portOption);

    options.addOption(COMMANDLINE_OPTION_LENIENT, false, Messages.CommandlineOptionLenient);
    options.addOption(COMMANDLINE_OPTION_HELP, false, Messages.CommandlineOptionHelp);

    OptionGroup verbosityOptions = new OptionGroup();
    verbosityOptions.addOption(new Option(COMMANDLINE_OPTION_QUIET, false, Messages.CommandlineOptionQuiet));
    verbosityOptions
            .addOption(new Option(COMMANDLINE_OPTION_VERBOSE, false, Messages.CommandlineOptionVerbose));
    options.addOptionGroup(verbosityOptions);

    OptionGroup startStopOptions = new OptionGroup();
    startStopOptions.addOption(new Option(COMMANDLINE_OPTION_START, false, Messages.CommandlineOptionStart));

    OptionBuilder.hasOptionalArg();
    Option stopOption = OptionBuilder.create(COMMANDLINE_OPTION_STOP);
    stopOption.setDescription(NLS.bind(Messages.OptionStopDescription, DEFAULT_HOSTNAME_LOCALHOST));
    stopOption.setArgName(HOSTNAME);
    startStopOptions.addOption(stopOption);
    options.addOptionGroup(startStopOptions);

    return options;
}

From source file:org.eclipse.jubula.app.autrun.AutRunApplication.java

/**
 * @return the command line options available when invoking the main method. 
 *///  ww w  .  jav a 2  s  .  c o  m
private static Options createCmdLineOptions() {
    Options options = new Options();
    Option autAgentHostOption = new Option(OPT_AUT_AGENT_HOST, true,
            NLS.bind(Messages.infoAutAgentHost, DEFAULT_AUT_AGENT_HOST));
    autAgentHostOption.setLongOpt(OPT_AUT_AGENT_HOST_LONG);
    autAgentHostOption.setArgName(HOSTNAME);
    options.addOption(autAgentHostOption);

    Option autAgentPortOption = new Option(OPT_AUT_AGENT_PORT, true,
            NLS.bind(Messages.infoAutAgentPort, DEFAULT_AUT_AGENT_PORT));
    autAgentPortOption.setLongOpt(OPT_AUT_AGENT_PORT_LONG);
    autAgentPortOption.setArgName(PORT);
    options.addOption(autAgentPortOption);

    OptionGroup autToolkitOptionGroup = new OptionGroup();
    autToolkitOptionGroup.addOption(new Option(TK_SWING, Messages.infoSwingToolkit));
    autToolkitOptionGroup.addOption(new Option(TK_SWT, Messages.infoSwtToolkit));
    autToolkitOptionGroup.addOption(new Option(TK_RCP, Messages.infoRcpToolkit));
    autToolkitOptionGroup.setRequired(true);
    options.addOptionGroup(autToolkitOptionGroup);

    Option autIdOption = new Option(OPT_AUT_ID, true, Messages.infoAutId);
    autIdOption.setLongOpt(OPT_AUT_ID_LONG);
    autIdOption.setArgName(ID);
    autIdOption.setRequired(true);
    options.addOption(autIdOption);

    Option nameTechnicalComponentsOption = new Option(OPT_NAME_TECHNICAL_COMPONENTS, true,
            Messages.infoGenerateTechnicalComponentNames);
    nameTechnicalComponentsOption.setLongOpt(OPT_NAME_TECHNICAL_COMPONENTS_LONG);
    nameTechnicalComponentsOption.setArgName(TRUE_FALSE);
    options.addOption(nameTechnicalComponentsOption);

    Option keyboardLayoutOption = new Option(OPT_KEYBOARD_LAYOUT, true, Messages.infoKbLayout);
    keyboardLayoutOption.setLongOpt(OPT_KEYBOARD_LAYOUT_LONG);
    keyboardLayoutOption.setArgName(LOCALE);
    options.addOption(keyboardLayoutOption);

    Option workingDirOption = new Option(OPT_WORKING_DIR, true, Messages.infoAutWorkingDirectory);
    workingDirOption.setLongOpt(OPT_WORKING_DIR_LONG);
    workingDirOption.setArgName(DIRECTORY);
    options.addOption(workingDirOption);

    Option helpOption = new Option(OPT_HELP, false, Messages.infoHelp);
    helpOption.setLongOpt(OPT_HELP_LONG);
    options.addOption(helpOption);

    OptionBuilder.hasArgs();
    Option autExecutableFileOption = OptionBuilder.create(OPT_EXECUTABLE);
    autExecutableFileOption.setDescription(Messages.infoExecutableFile);
    autExecutableFileOption.setLongOpt(OPT_EXECUTABLE_LONG);
    autExecutableFileOption.setRequired(true);
    autExecutableFileOption.setArgName(COMMAND);
    options.addOption(autExecutableFileOption);

    return options;
}

From source file:org.globus.workspace.client_common.TempBaseClient.java

protected CommandLine parse(String[] args, Properties defaultOptions) throws Exception {
    CommandLineParser parser = new PosixParser();
    CommandLine line = parser.parse(options, args, defaultOptions);

    if (defaultOptions != null) {
        Iterator iter = defaultOptions.entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry entry = (Map.Entry) iter.next();
            Option opt = options.getOption((String) entry.getKey());
            if (opt != null) {
                String desc = opt.getDescription();
                desc += " (Default '" + entry.getValue() + "')";
                opt.setDescription(desc);
            }/*  w w  w .  ja  v a 2 s.c  o  m*/
        }
    }

    if (line.hasOption("h")) {
        displayUsage();
        System.exit(0);
    }

    if (line.hasOption("e")) {
        if (line.hasOption("k")) {
            throw new ParseException("-e and -k arguments are exclusive");
        }
        if (line.hasOption("s")) {
            throw new ParseException("-e and -s arguments are exclusive");
        }

        FileInputStream in = null;
        try {
            in = new FileInputStream(line.getOptionValue("e"));
            this.endpoint = (EndpointReferenceType) ObjectDeserializer.deserialize(new InputSource(in),
                    EndpointReferenceType.class);
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (Exception e) {
                }
            }
        }
    } else if (line.hasOption("s")) {
        this.endpoint = new EndpointReferenceType();
        this.endpoint.setAddress(new Address(line.getOptionValue("s")));
    } else {
        throw new ParseException("-s or -e argument is required");
    }

    if (line.hasOption("k")) {
        String[] values = line.getOptionValues("k");
        if (values.length != 2) {
            throw new ParseException("-k requires two arguments");
        }
        QName keyName = QName.valueOf(values[0]);
        ReferencePropertiesType props = new ReferencePropertiesType();
        SimpleResourceKey key = new SimpleResourceKey(keyName, values[1]);
        props.add(key.toSOAPElement());
        this.endpoint.setProperties(props);
    }

    this.debugMode = line.hasOption("d");

    // Security mechanism
    if (line.hasOption("m")) {
        String value = line.getOptionValue("m");
        if (value != null) {
            if (value.equals("msg")) {
                this.mechanism = Constants.GSI_SEC_MSG;
            } else if (value.equals("conv")) {
                this.mechanism = Constants.GSI_SEC_CONV;
            } else {
                throw new ParseException("Unsupported security mechanism: " + value);
            }
        }
    }

    // Protection
    if (line.hasOption("p")) {
        String value = line.getOptionValue("p");
        if (value != null) {
            if (value.equals("sig")) {
                this.protection = Constants.SIGNATURE;
            } else if (value.equals("enc")) {
                this.protection = Constants.ENCRYPTION;
            } else {
                throw new ParseException("Unsupported protection mode: " + value);
            }
        }
    }

    // Delegation
    if (line.hasOption("g")) {
        String value = line.getOptionValue("g");
        if (value != null) {
            if (value.equals("limited")) {
                this.delegation = GSIConstants.GSI_MODE_LIMITED_DELEG;
            } else if (value.equals("full")) {
                this.delegation = GSIConstants.GSI_MODE_FULL_DELEG;
            } else {
                throw new ParseException("Unsupported delegation mode: " + value);
            }
        }
    }

    // Authz
    if (line.hasOption("z")) {
        String value = line.getOptionValue("z");
        if (value != null) {
            if (value.equals("self")) {
                this.authorization = SelfAuthorization.getInstance();
            } else if (value.equals("host")) {
                this.authorization = HostAuthorization.getInstance();
            } else if (value.equals("none")) {
                this.authorization = NoAuthorization.getInstance();
            } else if (authorization == null) {
                this.authorization = new IdentityAuthorization(value);
            }
        }
    }

    // Anonymous
    if (line.hasOption("a")) {
        this.anonymous = Boolean.TRUE;
    }

    // context lifetime
    if (line.hasOption("l")) {
        String value = line.getOptionValue("l");
        if (value != null)
            this.contextLifetime = new Integer(value);
    }

    // msg actor
    if (line.hasOption("x")) {
        String value = line.getOptionValue("x");
        this.msgActor = value;
    }

    // conv actor
    if (line.hasOption("y")) {
        String value = line.getOptionValue("y");
        this.convActor = value;
    }

    // Server's public key
    if (line.hasOption("c")) {
        String value = line.getOptionValue("c");
        this.publicKeyFilename = value;
    }

    if (line.hasOption("f")) {
        String value = line.getOptionValue("f");
        this.descriptorFile = value;
    }

    return line;
}

From source file:uk.ac.ed.bio.SynthSys.SBMLDataTools.SBMLAddTimeCourseData.java

/**
 * Gets the command line options.  This includes details to get their arguments in necessary
 * and descriptions required to display help message.
 * /*from  w  ww  .  j av a  2  s .co m*/
 * @return command line options
 */
private static Options getCommandLineOptions() {
    Options options = new Options();

    Option option;

    // help
    option = Option.builder(OPTION_HELP).build();
    option.setDescription("Displays this help message");
    options.addOption(option);

    // csvIn
    option = Option.builder(OPTION_CSV_IN).hasArg(true).argName("file").build();
    option.setDescription("csv time course data file. Optional: if not specified stdin will be used.");
    options.addOption(option);

    // csvOut
    option = Option.builder(OPTION_CSV_OUT).hasArg(true).argName("file").build();
    option.setDescription("csv file to write fitted data. Optional.");
    options.addOption(option);

    // sbmlIn
    option = Option.builder(OPTION_SBML_IN).hasArg(true).argName("file").build();
    option.setDescription("Input SBML file. Optional: if not specified an empty model will be used.");
    options.addOption(option);

    // sbmlLevel
    option = Option.builder(OPTION_SBML_LEVEL).hasArg(true).argName("level").build();
    option.setDescription("SBML level of SBML model if no SBML input file is specified. Optional. "
            + "Default is " + DEFAULT_SBML_LEVEL);
    options.addOption(option);

    // sbmlVerison
    option = Option.builder(OPTION_SBML_VERSION).hasArg(true).argName("version").build();
    option.setDescription("SBML version of SBML model if no SBML input file is specified. Optional. "
            + "Default is " + DEFAULT_SBML_VERSION);
    options.addOption(option);

    // sbmlOut 
    option = Option.builder(OPTION_SBML_OUT).hasArg(true).argName("file").build();
    option.setDescription("Output SBML file. Optional.");
    options.addOption(option);

    // csvSeparator
    option = Option.builder(OPTION_CSV_SEPARATOR).hasArg(true).argName("separator").build();
    option.setDescription("Single character separator used between fields of CSV file "
            + "(or TAB can be used for a tab character). " + "Optional. Default is comma ','.");
    options.addOption(option);

    // interpolator
    option = Option.builder(OPTION_INTERPOLATOR).hasArg(true).argName("interpolator").build();
    option.setDescription("Interpolator to use: one of 'linear' or 'cubic' " + "Optional. Default is linear.");
    options.addOption(option);

    return options;
}