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

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

Introduction

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

Prototype

public void setArgs(int num) 

Source Link

Document

Sets the number of argument values this Option can take.

Usage

From source file:com.zimbra.common.localconfig.LocalConfigUpgrade.java

private static Options getAllOptions() {
    Options options = new Options();
    options.addOption(O_HELP, "help", false, "print usage");
    options.addOption(O_CONFIG, "config", true, "path to localconfig.xml");
    options.addOption(O_TAG, "tag", true, "backup and tag with this suffix");
    Option bugOpt = new Option(O_BUG, "bug", true, "bug number this upgrade is for (multiple allowed)");
    bugOpt.setArgs(Option.UNLIMITED_VALUES);
    options.addOption(bugOpt);/*from www .  j  av  a  2s.c om*/
    return options;
}

From source file:lu.tudor.santec.dicom.gui.header.Dcm2Xml.java

private static CommandLine parse(String[] args) {
    Options opts = new Options();
    Option basedir = new Option("d", true, "store extracted values in files under <basedir>. Cannot be "
            + "specified together with option -o <xmlfile>.");
    basedir.setArgName("basedir");
    opts.addOption(basedir);/*from  www  . j  av  a  2 s .  c o m*/
    Option xmlfile = new Option("o", true, "file to write XML to, standard output by default");
    xmlfile.setArgName("xmlfile");
    opts.addOption(xmlfile);
    Option exclude = new Option("x", true,
            "tag (e.g.: 7FE00010) or name (e.g.: PixelData) of attribute " + "to exclude from XML output");
    exclude.setArgName("tag");
    opts.addOption(exclude);
    opts.addOption("X", false, "exclude pixel data from XML output " + "(= shortcut for -x 7FE00010).");
    Option xslurl = new Option("T", true, "transform XML output by applying specified XSL stylesheet.");
    xslurl.setArgName("xslurl");
    opts.addOption(xslurl);
    Option xsltparams = new Option("P", true, "pass specified parameters to the XSL stylesheet.");
    xsltparams.setArgName("param=value,...");
    xsltparams.setValueSeparator('=');
    xsltparams.setArgs(2);
    opts.addOption(xsltparams);
    opts.addOption("I", "incxslt", false, "enable incremental XSLT");
    opts.addOption("c", "compact", false, "suppress additional whitespaces in XML output");
    opts.addOption("C", "comments", false, "include attribute names as comments in XML output");
    opts.addOption("h", "help", false, "print this message");
    opts.addOption("V", "version", false, "print the version information and exit");
    CommandLine cl = null;
    try {
        cl = new PosixParser().parse(opts, args);
    } catch (ParseException e) {
        exit("dcm2xml: " + e.getMessage());
        throw new RuntimeException("unreachable");
    }
    if (cl.hasOption('V')) {
        Package p = Dcm2Xml.class.getPackage();
        System.out.println("dcm2xml v" + p.getImplementationVersion());
        System.exit(0);
    }
    if (cl.hasOption('h') || cl.getArgList().isEmpty()) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(USAGE, DESCRIPTION, opts, EXAMPLE);
        System.exit(0);
    }
    if (cl.hasOption("o") && cl.hasOption("d"))
        exit("dcm2xml: Option -o <xmlfile> and -d <basedir> are mutual" + "exclusive");
    return cl;
}

From source file:at.ac.tuwien.ims.latex2mobiformulaconv.app.Main.java

private static void initializeOptions() {
    options = new Options();

    Option inputOption = new Option("i", "inputPaths", true, "inputPaths file");
    inputOption.setRequired(true);// w  ww .j  av a2 s . co  m
    inputOption.setArgs(Option.UNLIMITED_VALUES);
    inputOption.setOptionalArg(false);
    inputOption.setValueSeparator(',');
    options.addOption(inputOption);

    options.addOption("f", "filename", true, "output filename");
    options.addOption("o", "output-dir", true, "output directory");
    options.addOption("m", "export-markup", false, "export html markup");
    options.addOption("n", "no-mobi", false, "no Mobi conversion, just markup, NOTE: makes -m implicit!");
    options.addOption("t", "title", true, "Document title");
    options.addOption("h", "help", false, "show this help");
    options.addOption("d", "debugMarkupOutput", false, "show debug output in html markup");
    options.addOption("u", "use-calibre", false, "use calibre ebook-convert instead of kindlegen");

    Option picturesOption = new Option("r", "replace latex formulas with pictures, override html");
    picturesOption.setLongOpt("replace-with-images");
    picturesOption.setArgs(0);
    picturesOption.setRequired(false);
    options.addOption(picturesOption);

    // implementation specific options
    options.addOption(
            ((LatexToHtmlConverter) applicationContext.getBean("latex2html-converter")).getExecOption());
    options.addOption(
            ((HtmlToMobiConverter) applicationContext.getBean(KINDLEGEN_HTML2MOBI_CONVERTER)).getExecOption());
    options.addOption(
            ((HtmlToMobiConverter) applicationContext.getBean(CALIBRE_HTML2MOBI_CONVERTER)).getExecOption());
}

From source file:fr.inria.atlanmod.emf.graphs.Connectedness.java

/**
 * Creates the program options/*from   w w w.j  a v  a 2  s . c  o  m*/
 * 
 * @param options
 * @return
 */
private static Options createOptions() {

    Options options = new Options();

    Option inputMetamodelOpt = OptionBuilder.create(INPUT_METAMODEL);
    inputMetamodelOpt.setLongOpt(INPUT_METAMODEL_LONG);
    inputMetamodelOpt.setArgName("source.ecore");
    inputMetamodelOpt.setDescription("Path of the source metamodel file");
    inputMetamodelOpt.setArgs(1);
    inputMetamodelOpt.setRequired(true);

    Option inputModelOpt = OptionBuilder.create(INPUT_MODEL);
    inputModelOpt.setLongOpt(INPUT_MODEL_LONG);
    inputModelOpt.setArgName("input.xmi");
    inputModelOpt.setDescription("Path of the input file");
    inputModelOpt.setArgs(1);
    inputModelOpt.setRequired(true);

    Option logUnreachableOpt = OptionBuilder.create(LOG_UNREACHABLE);
    logUnreachableOpt.setLongOpt(LOG_UNREACHABLE_LONG);
    logUnreachableOpt.setDescription("Log information about unreachable objects");
    logUnreachableOpt.setArgs(0);
    logUnreachableOpt.setRequired(false);

    options.addOption(inputMetamodelOpt);
    options.addOption(inputModelOpt);
    options.addOption(logUnreachableOpt);

    return options;
}

From source file:com.linkedin.helix.examples.BootstrapProcess.java

@SuppressWarnings("static-access")
private static Options constructCommandLineOptions() {
    Option helpOption = OptionBuilder.withLongOpt(help).withDescription("Prints command-line options info")
            .create();/*  w w  w . ja  v a  2s .  co m*/

    Option zkServerOption = OptionBuilder.withLongOpt(zkServer).withDescription("Provide zookeeper address")
            .create();
    zkServerOption.setArgs(1);
    zkServerOption.setRequired(true);
    zkServerOption.setArgName("ZookeeperServerAddress(Required)");

    Option clusterOption = OptionBuilder.withLongOpt(cluster).withDescription("Provide cluster name").create();
    clusterOption.setArgs(1);
    clusterOption.setRequired(true);
    clusterOption.setArgName("Cluster name (Required)");

    Option hostOption = OptionBuilder.withLongOpt(hostAddress).withDescription("Provide host name").create();
    hostOption.setArgs(1);
    hostOption.setRequired(true);
    hostOption.setArgName("Host name (Required)");

    Option portOption = OptionBuilder.withLongOpt(hostPort).withDescription("Provide host port").create();
    portOption.setArgs(1);
    portOption.setRequired(true);
    portOption.setArgName("Host port (Required)");

    Option stateModelOption = OptionBuilder.withLongOpt(stateModel).withDescription("StateModel Type").create();
    stateModelOption.setArgs(1);
    stateModelOption.setRequired(true);
    stateModelOption.setArgName("StateModel Type (Required)");

    // add an option group including either --zkSvr or --configFile
    Option fileOption = OptionBuilder.withLongOpt(configFile)
            .withDescription("Provide file to read states/messages").create();
    fileOption.setArgs(1);
    fileOption.setRequired(true);
    fileOption.setArgName("File to read states/messages (Optional)");

    Option transDelayOption = OptionBuilder.withLongOpt(transDelay).withDescription("Provide state trans delay")
            .create();
    transDelayOption.setArgs(1);
    transDelayOption.setRequired(false);
    transDelayOption.setArgName("Delay time in state transition, in MS");

    OptionGroup optionGroup = new OptionGroup();
    optionGroup.addOption(zkServerOption);
    optionGroup.addOption(fileOption);

    Options options = new Options();
    options.addOption(helpOption);
    // options.addOption(zkServerOption);
    options.addOption(clusterOption);
    options.addOption(hostOption);
    options.addOption(portOption);
    options.addOption(stateModelOption);
    options.addOption(transDelayOption);

    options.addOptionGroup(optionGroup);

    return options;
}

From source file:lee.util.jtap.JTapCli.java

public static Options constructOptions() {
    final Options options = new Options();
    options.addOption("h", false, "Print help for this application");
    options.addOption("dumpkeys", false, "Dumps keys for the specified bucket");
    options.addOption("dumpall", false, "Dumps keys and values for the specified bucket");

    Option session = OptionBuilder.withArgName("host,bucket,[password,port]").hasArg()
            .withDescription("host address of membase server, bucket name and optional port if not default.")
            .create("s");
    session.setLongOpt("session");
    session.setValueSeparator(',');
    session.setArgs(4);
    options.addOption(session);//from  ww w.j  ava2 s.  c  o m

    Option deleteKey = OptionBuilder.withArgName("key").hasArg().withDescription("key to be deleted.")
            .create("dk");
    deleteKey.setLongOpt("deletekey");
    options.addOption(deleteKey);

    Option getKey = OptionBuilder.withArgName("key").hasArg().withDescription("key to be retrieved.")
            .create("gk");
    getKey.setLongOpt("getkey");
    options.addOption(getKey);
    options.addOption("cs", "clearsession", false, "Clear session info from drive.");
    return options;
}

From source file:com.mebigfatguy.roomstore.RoomStore.java

private static Options createOptions() {
    Options options = new Options();

    Option option = new Option(NICK_NAME, true, "nickname to use to access irc channels");
    option.setRequired(true);//w w  w.ja va  2 s  .  com
    options.addOption(option);

    option = new Option(IRCSERVER, true, "irc server url");
    option.setRequired(true);
    options.addOption(option);

    option = new Option(CHANNELS, true, "space separated list of channels to connect to");
    option.setRequired(true);
    option.setArgs(100);
    options.addOption(option);

    option = new Option(ENDPOINTS, true, "space separated list of cassandra server server/ports");
    option.setOptionalArg(true);
    option.setRequired(false);
    option.setArgs(100);
    options.addOption(option);

    option = new Option(RF, true, "replication factor[default=1]");
    option.setRequired(false);
    options.addOption(option);

    return options;
}

From source file:de.zib.scalaris.Main.java

/**
 * Creates the options the command line should understand.
 * /*from  w  w  w  .  j a  va 2  s.  c o  m*/
 * @return the options the program understands
 */
private static Options getOptions() {
    Options options = new Options();
    OptionGroup group = new OptionGroup();

    /* Note: arguments are set to be optional since we implement argument
     * checks on our own (commons.cli is not flexible enough and only
     * checks for the existence of a first argument)
     */

    options.addOption(new Option("h", "help", false, "print this message"));

    options.addOption(new Option("v", "verbose", false, "print verbose information, e.g. the properties read"));

    Option read = new Option("r", "read", true, "read an item");
    read.setArgName("key");
    read.setArgs(1);
    read.setOptionalArg(true);
    group.addOption(read);

    Option write = new Option("w", "write", true, "write an item");
    write.setArgName("key> <value");
    write.setArgs(2);
    write.setOptionalArg(true);
    group.addOption(write);

    Option publish = new Option("p", "publish", true, "publish a new message for the given topic");
    publish.setArgName("topic> <message");
    publish.setArgs(2);
    publish.setOptionalArg(true);
    group.addOption(publish);

    Option subscribe = new Option("s", "subscribe", true, "subscribe to a topic");
    subscribe.setArgName("topic> <url");
    subscribe.setArgs(2);
    subscribe.setOptionalArg(true);
    group.addOption(subscribe);

    Option unsubscribe = new Option("u", "unsubscribe", true, "unsubscribe from a topic");
    unsubscribe.setArgName("topic> <url");
    unsubscribe.setArgs(2);
    unsubscribe.setOptionalArg(true);
    group.addOption(unsubscribe);

    Option getSubscribers = new Option("g", "getsubscribers", true, "get subscribers of a topic");
    getSubscribers.setArgName("topic");
    getSubscribers.setArgs(1);
    getSubscribers.setOptionalArg(true);
    group.addOption(getSubscribers);

    Option delete = new Option("d", "delete", true,
            "delete an item (default timeout: 2000ms)\n"
                    + "WARNING: This function can lead to inconsistent data (e.g. "
                    + "deleted items can re-appear). Also when re-creating an item "
                    + "the version before the delete can re-appear.");
    delete.setArgName("key> <[timeout]");
    delete.setArgs(2);
    delete.setOptionalArg(true);
    group.addOption(delete);

    options.addOption(new Option("b", "minibench", false, "run mini benchmark"));

    options.addOption(new Option("lh", "localhost", false,
            "gets the local host's name as known to Java (for debugging purposes)"));

    options.addOptionGroup(group);

    return options;
}

From source file:exm.stc.ui.Main.java

private static Options initOptions() {
    Options opts = new Options();

    Option module = new Option(INCLUDE_FLAG, "include", true, "Add to import search path");
    opts.addOption(module);/*  w  w w. j a v  a 2  s. c  o  m*/

    Option arg = new Option(SWIFT_PROG_ARG_FLAG, "arg", true, "Compile-time argument");
    arg.setArgs(2);
    arg.setValueSeparator('=');
    opts.addOption(arg);

    Option preprocArg = new Option(PREPROC_MACRO_FLAG, true, "Preprocessor definition");
    opts.addOption(preprocArg);

    opts.addOption(UPDATE_FLAG, false, "Update output only if out of date");
    return opts;
}

From source file:net.sf.markov4jmeter.behaviormodelextractor.CmdlOptionFactory.java

/**
 * Creates an option with a specified number of arguments;
 *
 * @param opt//from  w w w .j a v  a 2 s.  co  m
 *     Short representation of the option (e.g. <code>"s"</code>).
 * @param longOpt
 *     Long representation of the option
 *     (e.g. <code>"source-project"</code>).
 * @param description
 *     Description of the option
 *     (e.g. <code>"Path to source project."</code>).
 * @param isRequired
 *     Flag indicating whether the option is required (as a command-line
 *     argument) or not.
 * @param argName
 *     Display name for the argument value.
 * @param argsNum
 *     Number of arguments; a negative value indicates an infinite sequence
 *     of arguments.
 * @param hasOptionalArg
 *     <code>true</code> if and only if the arguments are optional.
 * @return
 *     An instance of {@link Option} with the specified properties.
 */
public static Option createOption(final String opt, final String longOpt, final String description,
        final boolean isRequired, final String argName, final int argsNum, final boolean hasOptionalArg) {

    final Option option = new Option(opt, longOpt, argsNum != 0 /* hasArg */, description);

    option.setRequired(isRequired);

    if (argsNum != 0) { // argsNum < 0 for infinite sequence of arguments;

        if (argName != null) {
            option.setArgName(argName);
        }
        // negative number of arguments implies an infinite sequence;
        option.setArgs((argsNum < 0) ? Integer.MAX_VALUE : argsNum);

        option.setValueSeparator(CmdlOptionFactory.DEFAULT_VALUE_SEPARATOR);
        option.setOptionalArg(hasOptionalArg);
    }
    return option;
}