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:net.kyllercg.acms.ACMgen.java

/**
 * Creates the valid command line options
 *///from   www. j  av  a 2  s .  c om
private void createOptions() {

    Option op_help = new Option("h", "help", false, ACMgen.msg.getMessage("help_desc"));

    Option op_rrbb = new Option("r", "rrbb", true, ACMgen.msg.getMessage("rrbb_desc"));
    op_rrbb.setArgs(1);
    op_rrbb.setArgName("size");
    Option op_owbb = new Option("o", "owbb", true, ACMgen.msg.getMessage("owbb_desc"));
    op_owbb.setArgs(1);
    op_owbb.setArgName("size");
    Option op_owrrbb = new Option("b", "owrrbb", true, ACMgen.msg.getMessage("owrrbb_desc"));
    op_owrrbb.setArgs(1);
    op_owrrbb.setArgName("size");

    Option op_cpp = new Option("C", "cpp", false, ACMgen.msg.getMessage("cpp_desc"));
    Option op_verilog = new Option("v", "verilog", false, ACMgen.msg.getMessage("verilog_desc"));
    Option op_pep = new Option("p", "pep", false, ACMgen.msg.getMessage("pep_desc"));
    Option op_petrify = new Option("P", "petrify", false, ACMgen.msg.getMessage("petrify_desc"));
    Option op_smv = new Option("s", "smv", false, ACMgen.msg.getMessage("smv_desc"));
    Option op_smv_pn = new Option("S", "smvpn", false, ACMgen.msg.getMessage("smvpn_desc"));

    OptionGroup op_acm_group = new OptionGroup();
    op_acm_group.setRequired(true);
    op_acm_group.addOption(op_help);
    op_acm_group.addOption(op_rrbb);
    op_acm_group.addOption(op_owbb);
    op_acm_group.addOption(op_owrrbb);

    this.options = new Options();
    this.options.addOptionGroup(op_acm_group);
    this.options.addOption(op_cpp);
    this.options.addOption(op_verilog);
    this.options.addOption(op_pep);
    this.options.addOption(op_petrify);
    this.options.addOption(op_smv);
    this.options.addOption(op_smv_pn);
}

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

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

    /////*from  w  ww  .j a  v a  2  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:de.bmw.yamaica.common.console.CommandExecuter.java

private Option createOption(IConfigurationElement optionConfiguration) {
    String shortName = optionConfiguration.getAttribute(OPTION_SHORT_NAME_ATTRIBUTE_NAME);
    String longName = optionConfiguration.getAttribute(OPTION_LONG_NAME_ATTRIBUTE_NAME);
    String description = optionConfiguration.getAttribute(OPTION_DESCRIPTION_ATTRIBUTE_NAME);
    String required = optionConfiguration.getAttribute(OPTION_REQUIRED_ATTRIBUTE_NAME);
    String argCount = optionConfiguration.getAttribute(OPTION_ARG_COUNT_ATTRIBUTE_NAME);
    String argName = optionConfiguration.getAttribute(OPTION_ARG_NAME_ATTRIBUTE_NAME);
    String hasOptionalArg = optionConfiguration.getAttribute(OPTION_HAS_OPTIONAL_ARG_ATTRIBUTE_NAME);
    String valueSeparator = optionConfiguration.getAttribute(OPTION_VALUE_SEPARATOR_ATTRIBUTE_NAME);

    Option option = new Option(shortName, description);
    option.setRequired(Boolean.parseBoolean(required));
    option.setArgs(Integer.parseInt(argCount));
    option.setOptionalArg(Boolean.parseBoolean(hasOptionalArg));

    if (null != longName) {
        option.setLongOpt(longName);//w  ww  .jav a  2s .c o  m
    }

    if (null != argName) {
        option.setArgName(argName);
    }

    if (null != valueSeparator) {
        option.setValueSeparator(valueSeparator.charAt(0));
    }

    return option;
}

From source file:de.uni_koblenz.jgralab.utilities.rsa2tg.SchemaGraph2XMI.java

/**
 * Processes all command line parameters and returns a {@link CommandLine}
 * object, which holds all values included in the given {@link String}
 * array.//from w  ww  .j a  v a  2 s  .  c  om
 * 
 * @param args
 *            {@link CommandLine} parameters.
 * @return {@link CommandLine} object, which holds all necessary values.
 */
public static CommandLine processCommandLineOptions(String[] args) {

    // Creates a OptionHandler.
    String toolString = "java " + SchemaGraph2XMI.class.getName();
    String versionString = JGraLab.getInfo(false);

    OptionHandler oh = new OptionHandler(toolString, versionString);

    // Several Options are declared.
    Option output = new Option("o", "output", true, "(required): the output xmi file name");
    output.setRequired(true);
    output.setArgName("file");
    oh.addOption(output);

    Option schemaGraph = new Option("ig", "inputSchemaGraph", true,
            "(required or -i):if set, the schemaGraph is converted into a xmi.");
    schemaGraph.setRequired(false);
    schemaGraph.setArgs(0);
    output.setArgName("file");
    oh.addOption(schemaGraph);

    Option schema = new Option("i", "inputSchema", true,
            "(required or -ig): TG-file of the schema which should be converted into a xmi.");
    schema.setRequired(false);
    schema.setArgName("file");
    oh.addOption(schema);

    // either graph or schema has to be provided
    OptionGroup input = new OptionGroup();
    input.addOption(schemaGraph);
    input.addOption(schema);
    input.setRequired(true);
    oh.addOptionGroup(input);

    Option bidirectional = new Option("b", "bidirectional", false,
            "(optional): If set the EdgeClasses are created as bidirectional associations.");
    bidirectional.setRequired(false);
    oh.addOption(bidirectional);

    return oh.parse(args);
}

From source file:com.flyhz.avengers.framework.AvengersClient.java

AvengersClient(Configuration conf) {

    batchId = System.currentTimeMillis();
    LOG.info("conf is {},batchId is {}", batchId, conf);
    this.conf = conf;
    System.setProperty("HADOOP_USER_NAME", "avengers");
    yarnClient = YarnClient.createYarnClient();
    conf.getSocketAddr(YarnConfiguration.RM_ADDRESS, YarnConfiguration.DEFAULT_RM_ADDRESS,
            YarnConfiguration.DEFAULT_RM_PORT);

    yarnClient.init(conf);/*from  w  ww  . j a  va  2  s.c o  m*/

    opts = new Options();
    opts.addOption("jar", true, "Jar file containing the application master");

    Option all = new Option("all", false, "avengers all:include crawl fetch analyze");
    all.setArgs(0);

    Option crawl = new Option("crawl", true, "avengers crawl");
    crawl.setArgs(1);
    crawl.setArgName("batchId");

    Option fetch = new Option("fetch", true, "avengers fetch");
    fetch.setArgs(1);
    fetch.setArgName("batchId");

    Option analyze = new Option("analyze", true, "avengers analyze");
    analyze.setArgs(1);
    analyze.setArgName("batchId");

    opts.addOption(all);
    opts.addOption(crawl);
    opts.addOption(fetch);
    opts.addOption(analyze);

    avengersProcessCmds = new LinkedHashMap<String, List<String>>();
    this.hdfsPath = "avengers/" + batchId + "/avengers.jar";
}

From source file:lcmc.ArgumentParser.java

public void parseOptionsAndReturnAutoArguments(String[] args) {
    final Options options = new Options();

    options.addOption("h", HELP_OP, false, "print this help");
    options.addOption(null, KEEP_HELPER_OP, false, "do not overwrite the lcmc-gui-helper program");
    options.addOption(null, RO_OP, false, "read only mode");
    options.addOption(null, OP_OP, false, "operator mode");
    options.addOption(null, ADMIN_OP, false, "administrator mode");
    options.addOption(null, OP_MODE_OP, true, "operating mode. <arg> can be:\n" + "ro - read only\n"
            + "op - operator\n" + "admin - administrator");
    options.addOption(null, NOLRM_OP, false, "do not show removed resources from LRM.");
    options.addOption("v", VERSION_OP, false, "print version");
    options.addOption(null, AUTO_OP, true, "ADVANCED USE: for testing");
    options.addOption(null, PCMKTEST_OP, true, "ADVANCED USE: for testing");
    options.addOption(null, DRBDTEST_OP, true, "ADVANCED USE: for testing");
    options.addOption(null, VMTEST_OP, true, "ADVANCED USE: for testing");
    options.addOption(null, GUITEST_OP, true, "ADVANCED USE: for testing");
    options.addOption(null, NO_UPGRADE_CHECK_OP, false, "disable upgrade check");
    options.addOption(null, NO_PLUGIN_CHECK_OP, false,
            "disable plugin check, DEPRECATED: there are no plugins");
    options.addOption(null, TIGHTVNC_OP, false, "enable tight vnc viewer");
    options.addOption(null, ULTRAVNC_OP, false, "enable ultra vnc viewer");
    options.addOption(null, REALVNC_OP, false, "enable real vnc viewer");
    options.addOption(null, BIGDRBDCONF_OP, false,
            "create one big drbd.conf, instead of many" + " files in drbd.d/ directory");
    options.addOption(null, STAGING_DRBD_OP, false, "enable more DRBD installation options");
    options.addOption(null, STAGING_PACEMAKER_OP, false, "enable more Pacemaker installation options");
    options.addOption(null, VNC_PORT_OFFSET_OP, true, "offset for port forwarding");
    options.addOption(null, SLOW_OP, false, "specify this if you have slow computer");
    options.addOption(null, RESTORE_MOUSE_OP, false, "ADVANCED USE: for testing");
    options.addOption(null, SCALE_OP, true, "scale fonts and sizes of elements in percent (100)");
    options.addOption(null, ID_DSA_OP, true, "location of id_dsa file ($HOME/.ssh/id_dsa)");
    options.addOption(null, ID_RSA_OP, true, "location of id_rsa file ($HOME/.ssh/id_rsa)");
    options.addOption(null, KNOWN_HOSTS_OP, true, "location of known_hosts file ($HOME/.ssh/known_hosts)");
    options.addOption(null, OUT_OP, true, "where to redirect the standard out");
    options.addOption(null, DEBUG_OP, true, "debug level, 0 - none, 3 - all");
    options.addOption("c", CLUSTER_OP, true, "define a cluster");
    final Option hostOp = new Option("h", HOST_OP, true, "define a cluster, used with --cluster option");
    hostOp.setArgs(10000);
    options.addOption(hostOp);/*from   ww  w . j a va2  s . c  o  m*/
    options.addOption(null, SUDO_OP, false, "whether to use sudo, used with --cluster option");
    options.addOption(null, USER_OP, true, "user to use with sudo, used with --cluster option");
    options.addOption(null, PORT_OP, true, "ssh port, used with --cluster option");
    options.addOption(null, ADVANCED_OP, false, "start in an advanced mode");
    options.addOption(null, ONE_HOST_CLUSTER_OP, false, "allow one host cluster");
    options.addOption(null, NO_PASSPHRASE_OP, false, "try no passphrase first");
    options.addOption(null, EMBED_OP, false, "embed applet in the browser");
    options.addOption(null, NO_EMBED_OP, false, "don't embed applet in the browser");
    options.addOption(null, CMD_LOG_OP, false, "Log executed commands to the lcmc.log on the servers");
    options.addOption(null, CHECK_SWING_OP, false, "ADVANCED USE: for testing");
    final CommandLineParser parser = new PosixParser();
    String autoArgs = null;
    try {
        final CommandLine cmd = parser.parse(options, args);
        if (cmd.hasOption(OUT_OP)) {
            final String out = cmd.getOptionValue(OUT_OP);
            if (out != null) {
                try {
                    System.setOut(new PrintStream(new FileOutputStream(out)));
                } catch (final FileNotFoundException e) {
                    System.exit(2);
                }
            }
        }
        if (cmd.hasOption(DEBUG_OP)) {
            final String level = cmd.getOptionValue(DEBUG_OP);
            if (level != null && lcmc.common.domain.util.Tools.isNumber(level)) {
                LoggerFactory.setDebugLevel(Integer.parseInt(level));
            } else {
                throw new ParseException("cannot parse debug level: " + level);
            }
        }
        boolean tightvnc = cmd.hasOption(TIGHTVNC_OP);
        boolean ultravnc = cmd.hasOption(ULTRAVNC_OP);
        final boolean realvnc = cmd.hasOption(REALVNC_OP);
        if (!tightvnc && !ultravnc && !realvnc) {
            if (lcmc.common.domain.util.Tools.isLinux()) {
                tightvnc = true;
            } else {
                tightvnc = true;
                ultravnc = true;
            }
        }
        final boolean advanced = cmd.hasOption(ADVANCED_OP);
        access.setAdvancedMode(advanced);
        application.setUseTightvnc(tightvnc);
        application.setUseUltravnc(ultravnc);
        application.setUseRealvnc(realvnc);

        application.setUpgradeCheckEnabled(!cmd.hasOption(NO_UPGRADE_CHECK_OP));
        application.setBigDRBDConf(cmd.hasOption(BIGDRBDCONF_OP));
        application.setStagingDrbd(cmd.hasOption(STAGING_DRBD_OP));
        application.setStagingPacemaker(cmd.hasOption(STAGING_PACEMAKER_OP));
        application.setHideLRM(cmd.hasOption(NOLRM_OP));
        application.setKeepHelper(cmd.hasOption(KEEP_HELPER_OP));
        application.setOneHostCluster(cmd.hasOption(ONE_HOST_CLUSTER_OP));
        application.setNoPassphrase(cmd.hasOption(NO_PASSPHRASE_OP));
        if (cmd.hasOption(EMBED_OP)) {
            application.setEmbedApplet(true);
        }
        if (cmd.hasOption(NO_EMBED_OP)) {
            application.setEmbedApplet(false);
        }
        if (cmd.hasOption(CMD_LOG_OP)) {
            application.setCmdLog(true);
        }
        if (cmd.hasOption(CHECK_SWING_OP)) {
            swingUtils.setCheckSwing(true);
        }
        final String pwd = System.getProperty("user.home");
        final String scaleOp = cmd.getOptionValue(SCALE_OP, "100");
        try {
            final int scale = Integer.parseInt(scaleOp);
            application.setScale(scale);
            application.resizeFonts(scale);
        } catch (final NumberFormatException e) {
            LOG.appWarning("initApp: cannot parse scale: " + scaleOp);
        }

        final String idDsaPath = cmd.getOptionValue(ID_DSA_OP, pwd + "/.ssh/id_dsa");
        final String idRsaPath = cmd.getOptionValue(ID_RSA_OP, pwd + "/.ssh/id_rsa");
        final String knownHostsPath = cmd.getOptionValue(KNOWN_HOSTS_OP, pwd + "/.ssh/known_hosts");
        application.setIdDSAPath(idDsaPath);
        application.setIdRSAPath(idRsaPath);
        application.setKnownHostPath(knownHostsPath);

        final String opMode = cmd.getOptionValue(OP_MODE_OP);
        autoArgs = cmd.getOptionValue(AUTO_OP);
        if (cmd.hasOption(HELP_OP)) {
            final HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("java -jar LCMC.jar [OPTIONS]", options);
            System.exit(0);
        }
        if (cmd.hasOption(VERSION_OP)) {
            System.out.println("LINUX CLUSTER MANAGEMENT CONSOLE " + lcmc.common.domain.util.Tools.getRelease()
                    + " by Rasto Levrinc");
            System.exit(0);
        }
        if (cmd.hasOption("ro") || "ro".equals(opMode)) {
            access.setAccessType(AccessMode.RO);
            access.setMaxAccessType(AccessMode.RO);
        } else if (cmd.hasOption("op") || "op".equals(opMode)) {
            access.setAccessType(AccessMode.OP);
            access.setMaxAccessType(AccessMode.OP);
        } else if (cmd.hasOption("admin") || "admin".equals(opMode)) {
            access.setAccessType(AccessMode.ADMIN);
            access.setMaxAccessType(AccessMode.ADMIN);
        } else if (opMode != null) {
            LOG.appWarning("initApp: unknown operating mode: " + opMode);
        }
        float fps = MainData.DEFAULT_ANIM_FPS;
        if (cmd.hasOption(SLOW_OP)) {
            fps /= 2;
        }
        if (cmd.hasOption(RESTORE_MOUSE_OP)) {
            /* restore mouse if it is stuck in pressed state, during
            * robot tests. */
            roboTest.restoreMouse();
        }
        final String vncPortOffsetString = cmd.getOptionValue(VNC_PORT_OFFSET_OP);
        if (vncPortOffsetString != null && lcmc.common.domain.util.Tools.isNumber(vncPortOffsetString)) {
            application.setVncPortOffset(Integer.parseInt(vncPortOffsetString));
        }
        mainData.setAnimFPS(fps);
        if (cmd.hasOption(CLUSTER_OP) || cmd.hasOption(HOST_OP)) {
            parseClusterOptionsAndCreateClusterButton(cmd);
        }
    } catch (final ParseException exp) {
        System.out.println("ERROR: " + exp.getMessage());
        System.exit(1);
    }
    LOG.debug1("initApp: max mem: " + Runtime.getRuntime().maxMemory() / 1024 / 1024 + 'm');
    if (autoArgs != null) {
        parseAutoArgs(autoArgs);
    }
}

From source file:com.nilostep.xlsql.ui.XlUi.java

/**
 * Setter for property state.//from   w w  w .j  a v  a2 s .c  om
 * @param newstate New value of property state.
 */
public final void setState(final int newstate) {
    state = newstate;

    Option option;

    if (state == IDLE) {
        options = new Options();
        options.addOption("c", true, "[ config ]");
        options.addOption("h", false, "help");
        options.addOption("quit", false, "end xldba session");
        options.addOption("t", false, "display time");
    } else if (state == CONNECTED) {
        options = new Options();
        options.addOption("d", false, "disconnect");
        option = new Option("engine", true, "[ SET | ADD | REMOVE ] [ name ]");
        option.setArgs(2);
        options.addOption(option);
        options.addOption("h", false, "help");
        options.addOption("o", false, "open database");
        options.addOption("open", true, "[ path ]");
        options.addOption("ping", false, "ping engine");
        options.addOption("quit", false, "end xldba session");
        options.addOption("read", true, "[ path ]");
        options.addOption("r", false, "open database for read");
        option = new Option("set", true, "[ parameter ] [ value ]");
        option.setArgs(2);
        options.addOption(option);
        options.addOption("show", true, "[ ALL | parameter ]");
        options.addOption("t", false, "display time");
    } else if (state == READ) {
        options = new Options();
        options.addOption("cat", false, "catalog");
        options.addOption("close", false, "close");
        option = new Option("export", true,
                "[ ALL | (sch.)tab ] AS [ hsqldb | mysql | xml ] TO [ path | engine | out ]");
        option.setArgs(5);
        options.addOption(option);
        options.addOption("h", false, "help");
        options.addOption("quit", false, "end xldba session");
        options.addOption("t", false, "display time");
    } else if (state == OPEN) {
        options = new Options();
        options.addOption("close", false, "close");
        option = new Option("dir2xl", true,
                "[ all | files | subdirs ] in [ path ] as [ list | tree ] to " + " [ (schema.)table ]");
        option.setArgs(7);
        options.addOption(option);
        options.addOption("h", false, "help");
        options.addOption("quit", false, "end xldba session");
        options.addOption("sql", false, "interactive SQL session");
        options.addOption("script", true, "[ file ] run SQL script");
        options.addOption("t", false, "display time");
    }
}

From source file:com.linkedin.helix.tools.ClusterSetup.java

@SuppressWarnings("static-access")
private static Options constructCommandLineOptions() {
    Option helpOption = OptionBuilder.withLongOpt(help).withDescription("Prints command-line options info")
            .create();/*from   w ww  .j a  v  a2  s  . c  o  m*/

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

    Option listClustersOption = OptionBuilder.withLongOpt(listClusters)
            .withDescription("List existing clusters").create();
    listClustersOption.setArgs(0);
    listClustersOption.setRequired(false);

    Option listResourceOption = OptionBuilder.withLongOpt(listResources)
            .withDescription("List resources hosted in a cluster").create();
    listResourceOption.setArgs(1);
    listResourceOption.setRequired(false);
    listResourceOption.setArgName("clusterName");

    Option listInstancesOption = OptionBuilder.withLongOpt(listInstances)
            .withDescription("List Instances in a cluster").create();
    listInstancesOption.setArgs(1);
    listInstancesOption.setRequired(false);
    listInstancesOption.setArgName("clusterName");

    Option addClusterOption = OptionBuilder.withLongOpt(addCluster).withDescription("Add a new cluster")
            .create();
    addClusterOption.setArgs(1);
    addClusterOption.setRequired(false);
    addClusterOption.setArgName("clusterName");

    Option activateClusterOption = OptionBuilder.withLongOpt(activateCluster)
            .withDescription("Enable/disable a cluster in distributed controller mode").create();
    activateClusterOption.setArgs(3);
    activateClusterOption.setRequired(false);
    activateClusterOption.setArgName("clusterName grandCluster true/false");

    Option deleteClusterOption = OptionBuilder.withLongOpt(dropCluster).withDescription("Delete a cluster")
            .create();
    deleteClusterOption.setArgs(1);
    deleteClusterOption.setRequired(false);
    deleteClusterOption.setArgName("clusterName");

    Option addInstanceOption = OptionBuilder.withLongOpt(addInstance)
            .withDescription("Add a new Instance to a cluster").create();
    addInstanceOption.setArgs(2);
    addInstanceOption.setRequired(false);
    addInstanceOption.setArgName("clusterName InstanceAddress(host:port)");

    Option addResourceOption = OptionBuilder.withLongOpt(addResource)
            .withDescription("Add a resource to a cluster").create();
    addResourceOption.setArgs(4);
    addResourceOption.setRequired(false);
    addResourceOption.setArgName("clusterName resourceName partitionNum stateModelRef <-mode modeValue>");

    Option expandResourceOption = OptionBuilder.withLongOpt(expandResource)
            .withDescription("Expand resource to additional nodes").create();
    expandResourceOption.setArgs(2);
    expandResourceOption.setRequired(false);
    expandResourceOption.setArgName("clusterName resourceName");

    Option expandClusterOption = OptionBuilder.withLongOpt(expandCluster)
            .withDescription("Expand a cluster and all the resources").create();
    expandClusterOption.setArgs(1);
    expandClusterOption.setRequired(false);
    expandClusterOption.setArgName("clusterName");

    Option resourceModeOption = OptionBuilder.withLongOpt(mode)
            .withDescription("Specify resource mode, used with addResourceGroup command").create();
    resourceModeOption.setArgs(1);
    resourceModeOption.setRequired(false);
    resourceModeOption.setArgName("IdealState mode");

    Option resourceBucketSizeOption = OptionBuilder.withLongOpt(bucketSize)
            .withDescription("Specify size of a bucket, used with addResourceGroup command").create();
    resourceBucketSizeOption.setArgs(1);
    resourceBucketSizeOption.setRequired(false);
    resourceBucketSizeOption.setArgName("Size of a bucket for a resource");

    Option resourceKeyOption = OptionBuilder.withLongOpt(resourceKeyPrefix)
            .withDescription("Specify resource key prefix, used with rebalance command").create();
    resourceKeyOption.setArgs(1);
    resourceKeyOption.setRequired(false);
    resourceKeyOption.setArgName("Resource key prefix");

    Option addStateModelDefOption = OptionBuilder.withLongOpt(addStateModelDef)
            .withDescription("Add a State model to a cluster").create();
    addStateModelDefOption.setArgs(2);
    addStateModelDefOption.setRequired(false);
    addStateModelDefOption.setArgName("clusterName <filename>");

    Option addIdealStateOption = OptionBuilder.withLongOpt(addIdealState)
            .withDescription("Add a State model to a cluster").create();
    addIdealStateOption.setArgs(3);
    addIdealStateOption.setRequired(false);
    addIdealStateOption.setArgName("clusterName resourceName <filename>");

    Option dropInstanceOption = OptionBuilder.withLongOpt(dropInstance)
            .withDescription("Drop an existing Instance from a cluster").create();
    dropInstanceOption.setArgs(2);
    dropInstanceOption.setRequired(false);
    dropInstanceOption.setArgName("clusterName InstanceAddress(host:port)");

    Option swapInstanceOption = OptionBuilder.withLongOpt(swapInstance)
            .withDescription("Swap an old instance from a cluster with a new instance").create();
    swapInstanceOption.setArgs(3);
    swapInstanceOption.setRequired(false);
    swapInstanceOption.setArgName("clusterName oldInstance newInstance");

    Option dropResourceOption = OptionBuilder.withLongOpt(dropResource)
            .withDescription("Drop an existing resource from a cluster").create();
    dropResourceOption.setArgs(2);
    dropResourceOption.setRequired(false);
    dropResourceOption.setArgName("clusterName resourceName");

    Option rebalanceOption = OptionBuilder.withLongOpt(rebalance)
            .withDescription("Rebalance a resource in a cluster").create();
    rebalanceOption.setArgs(3);
    rebalanceOption.setRequired(false);
    rebalanceOption.setArgName("clusterName resourceName replicas");

    Option instanceInfoOption = OptionBuilder.withLongOpt(listInstanceInfo)
            .withDescription("Query info of a Instance in a cluster").create();
    instanceInfoOption.setArgs(2);
    instanceInfoOption.setRequired(false);
    instanceInfoOption.setArgName("clusterName InstanceName");

    Option clusterInfoOption = OptionBuilder.withLongOpt(listClusterInfo)
            .withDescription("Query info of a cluster").create();
    clusterInfoOption.setArgs(1);
    clusterInfoOption.setRequired(false);
    clusterInfoOption.setArgName("clusterName");

    Option resourceInfoOption = OptionBuilder.withLongOpt(listResourceInfo)
            .withDescription("Query info of a resource").create();
    resourceInfoOption.setArgs(2);
    resourceInfoOption.setRequired(false);
    resourceInfoOption.setArgName("clusterName resourceName");

    Option addResourcePropertyOption = OptionBuilder.withLongOpt(addResourceProperty)
            .withDescription("Add a resource property").create();
    addResourcePropertyOption.setArgs(4);
    addResourcePropertyOption.setRequired(false);
    addResourcePropertyOption.setArgName("clusterName resourceName propertyName propertyValue");

    Option removeResourcePropertyOption = OptionBuilder.withLongOpt(removeResourceProperty)
            .withDescription("Remove a resource property").create();
    removeResourcePropertyOption.setArgs(3);
    removeResourcePropertyOption.setRequired(false);
    removeResourcePropertyOption.setArgName("clusterName resourceName propertyName");

    Option partitionInfoOption = OptionBuilder.withLongOpt(listPartitionInfo)
            .withDescription("Query info of a partition").create();
    partitionInfoOption.setArgs(3);
    partitionInfoOption.setRequired(false);
    partitionInfoOption.setArgName("clusterName resourceName partitionName");

    Option enableInstanceOption = OptionBuilder.withLongOpt(enableInstance)
            .withDescription("Enable/disable a Instance").create();
    enableInstanceOption.setArgs(3);
    enableInstanceOption.setRequired(false);
    enableInstanceOption.setArgName("clusterName InstanceName true/false");

    Option enablePartitionOption = OptionBuilder.hasArgs().withLongOpt(enablePartition)
            .withDescription("Enable/disable partitions").create();
    enablePartitionOption.setRequired(false);
    enablePartitionOption.setArgName("true/false clusterName instanceName resourceName partitionName1...");

    Option enableClusterOption = OptionBuilder.withLongOpt(enableCluster)
            .withDescription("pause/resume the controller of a cluster").create();
    enableClusterOption.setArgs(2);
    enableClusterOption.setRequired(false);
    enableClusterOption.setArgName("clusterName true/false");

    Option resetPartitionOption = OptionBuilder.withLongOpt(resetPartition)
            .withDescription("Reset a partition in error state").create();
    resetPartitionOption.setArgs(4);
    resetPartitionOption.setRequired(false);
    resetPartitionOption.setArgName("clusterName instanceName resourceName partitionName");

    Option resetInstanceOption = OptionBuilder.withLongOpt(resetInstance)
            .withDescription("Reset all partitions in error state for an instance").create();
    resetInstanceOption.setArgs(2);
    resetInstanceOption.setRequired(false);
    resetInstanceOption.setArgName("clusterName instanceName");

    Option resetResourceOption = OptionBuilder.withLongOpt(resetResource)
            .withDescription("Reset all partitions in error state for a resource").create();
    resetResourceOption.setArgs(2);
    resetResourceOption.setRequired(false);
    resetResourceOption.setArgName("clusterName resourceName");

    Option listStateModelsOption = OptionBuilder.withLongOpt(listStateModels)
            .withDescription("Query info of state models in a cluster").create();
    listStateModelsOption.setArgs(1);
    listStateModelsOption.setRequired(false);
    listStateModelsOption.setArgName("clusterName");

    Option listStateModelOption = OptionBuilder.withLongOpt(listStateModel)
            .withDescription("Query info of a state model in a cluster").create();
    listStateModelOption.setArgs(2);
    listStateModelOption.setRequired(false);
    listStateModelOption.setArgName("clusterName stateModelName");

    Option addStatOption = OptionBuilder.withLongOpt(addStat).withDescription("Add a persistent stat").create();
    addStatOption.setArgs(2);
    addStatOption.setRequired(false);
    addStatOption.setArgName("clusterName statName");
    Option addAlertOption = OptionBuilder.withLongOpt(addAlert).withDescription("Add an alert").create();
    addAlertOption.setArgs(2);
    addAlertOption.setRequired(false);
    addAlertOption.setArgName("clusterName alertName");

    Option dropStatOption = OptionBuilder.withLongOpt(dropStat).withDescription("Drop a persistent stat")
            .create();
    dropStatOption.setArgs(2);
    dropStatOption.setRequired(false);
    dropStatOption.setArgName("clusterName statName");
    Option dropAlertOption = OptionBuilder.withLongOpt(dropAlert).withDescription("Drop an alert").create();
    dropAlertOption.setArgs(2);
    dropAlertOption.setRequired(false);
    dropAlertOption.setArgName("clusterName alertName");

    // set/get configs option
    Option setConfOption = OptionBuilder.withLongOpt(setConfig).withDescription("Set a config").create();
    setConfOption.setArgs(2);
    setConfOption.setRequired(false);
    setConfOption
            .setArgName("ConfigScope(e.g. CLUSTER=cluster,RESOURCE=rc,...) KeyValueMap(e.g. k1=v1,k2=v2,...)");

    Option getConfOption = OptionBuilder.withLongOpt(getConfig).withDescription("Get a config").create();
    getConfOption.setArgs(2);
    getConfOption.setRequired(false);
    getConfOption.setArgName("ConfigScope(e.g. CLUSTER=cluster,RESOURCE=rc,...) KeySet(e.g. k1,k2,...)");

    OptionGroup group = new OptionGroup();
    group.setRequired(true);
    group.addOption(rebalanceOption);
    group.addOption(addResourceOption);
    group.addOption(resourceModeOption);
    group.addOption(resourceBucketSizeOption);
    group.addOption(expandResourceOption);
    group.addOption(expandClusterOption);
    group.addOption(resourceKeyOption);
    group.addOption(addClusterOption);
    group.addOption(activateClusterOption);
    group.addOption(deleteClusterOption);
    group.addOption(addInstanceOption);
    group.addOption(listInstancesOption);
    group.addOption(listResourceOption);
    group.addOption(listClustersOption);
    group.addOption(addIdealStateOption);
    group.addOption(rebalanceOption);
    group.addOption(dropInstanceOption);
    group.addOption(swapInstanceOption);
    group.addOption(dropResourceOption);
    group.addOption(instanceInfoOption);
    group.addOption(clusterInfoOption);
    group.addOption(resourceInfoOption);
    group.addOption(partitionInfoOption);
    group.addOption(enableInstanceOption);
    group.addOption(enablePartitionOption);
    group.addOption(enableClusterOption);
    group.addOption(resetPartitionOption);
    group.addOption(resetInstanceOption);
    group.addOption(resetResourceOption);
    group.addOption(addStateModelDefOption);
    group.addOption(listStateModelsOption);
    group.addOption(listStateModelOption);
    group.addOption(addStatOption);
    group.addOption(addAlertOption);
    group.addOption(dropStatOption);
    group.addOption(dropAlertOption);
    group.addOption(setConfOption);
    group.addOption(getConfOption);
    group.addOption(addResourcePropertyOption);
    group.addOption(removeResourcePropertyOption);

    Options options = new Options();
    options.addOption(helpOption);
    options.addOption(zkServerOption);
    options.addOptionGroup(group);
    return options;
}

From source file:kieker.tools.logReplayer.FilesystemLogReplayerStarter.java

@Override
protected void addAdditionalOptions(final Options options) {
    Option option;

    option = new Option("c", CMD_OPT_NAME_MONITORING_CONFIGURATION, true,
            "Configuration to use for the Kieker monitoring instance");
    option.setArgName(OPTION_EXAMPLE_FILE_MONITORING_PROPERTIES);
    option.setRequired(false);/*from   www .  j a v a2s . c  om*/
    option.setValueSeparator('=');
    options.addOption(option);

    option = new Option("i", CMD_OPT_NAME_INPUTDIRS, true, "Log directories to read data from");
    option.setArgName("dir1 ... dirN");
    option.setRequired(false);
    option.setArgs(Option.UNLIMITED_VALUES);
    options.addOption(option);

    option = new Option("k", CMD_OPT_NAME_KEEPORIGINALLOGGINGTIMESTAMPS, true,
            "Replay the original logging timestamps (defaults to true)?");
    option.setArgName("true|false");
    option.setRequired(false);
    option.setValueSeparator('=');
    options.addOption(option);

    option = new Option("r", CMD_OPT_NAME_REALTIME, true, "Replay log data in realtime?");
    option.setArgName("true|false");
    option.setRequired(false);
    option.setValueSeparator('=');
    options.addOption(option);

    option = new Option("n", CMD_OPT_NAME_NUM_REALTIME_WORKERS, true,
            "Number of worker threads used in realtime mode (defaults to 1).");
    option.setArgName("num");
    option.setRequired(false);
    options.addOption(option);

    option = new Option("a", CMD_OPT_NAME_REALTIME_ACCELERATION_FACTOR, true,
            "Factor by which to accelerate (>1.0) or slow down (<1.0) the replay in realtime mode (defaults to 1.0, i.e., no acceleration/slow down).");
    option.setArgName("factor");
    option.setRequired(false);
    option.setValueSeparator('=');
    options.addOption(option);

    option = new Option(null, CMD_OPT_NAME_IGNORERECORDSBEFOREDATE, true,
            "Records logged before this date (UTC timezone) are ignored (disabled by default).");
    option.setArgName(DATE_FORMAT_PATTERN_CMD_USAGE_HELP);
    option.setRequired(false);
    options.addOption(option);

    option = new Option(null, CMD_OPT_NAME_IGNORERECORDSAFTERDATE, true,
            "Records logged after this date (UTC timezone) are ignored (disabled by default).");
    option.setArgName(DATE_FORMAT_PATTERN_CMD_USAGE_HELP);
    option.setRequired(false);
    options.addOption(option);
}

From source file:com.hablutzel.cmdline.CommandLineApplication.java

/**
 * This method scans the subclass for annotations
 * that denote the command line options and arguments,
 * and configures the systems so that the members that
 * have been annotated in that way are set up for calling
 * at command line processing time/*  w  w w.  j a  va  2 s.co m*/
 *
 */
private final void configure() throws CommandLineException {

    // Find all the fields in our subclass
    for (Method method : this.getClass().getDeclaredMethods()) {

        // If this method is marked with a  command line option, then configure
        // a corresponding commons-cli command line option here
        if (method.isAnnotationPresent(CommandLineOption.class)) {
            CommandLineOption commandLineOption = method.getDeclaredAnnotation(CommandLineOption.class);
            if (commandLineOption != null) {

                // Get the basic information about the option - the name and description
                String shortName = commandLineOption.shortForm().equals("") ? null
                        : commandLineOption.shortForm();
                String longName = commandLineOption.longForm().equals("") ? null : commandLineOption.longForm();
                String description = commandLineOption.usage();

                // If both the short and long name are null, then use the field name as the long name
                if (shortName == null && longName == null) {
                    longName = method.getName();
                }

                // The signature of the method determines what kind of command line
                // option is allowed. Basically, if the method does not take an argument,
                // then the option does not take arguments either. In this case, the
                // method is just called when the option is present.
                //
                // If the method does take argument, there are restrictions on the arguments
                // that are allowed. If there is a single argument, then the method will be
                // called for each argument supplied to the option. Generally in this case you
                // want the maximum number of option arguments to be 1, and you are just getting
                // the value of the argument. On the other hand, if the single argument is either
                // and array or a List<>, then the arguments will be passed in as an argument
                // or list respectively.
                //
                // Methods with more than 1 argument are not allowed. Methods with return types
                // other than boolean are not allowed. Methods that throw an exception other than
                // org.apache.commons.cli.CommandLineException are not allowed,
                //
                // If the method returns a boolean, and calling that method returns FALSE, then the
                // command line main function will not be called.
                //
                // The class of the argument has to be convertable using common-beanutils
                // conversion facilities
                CommandLineMethodHelper helper = getHelperForCommandOption(method, commandLineOption);

                // Now create and configure an option based on what the method is capable of handling
                // and the command line option parameters
                boolean allowsArguments = helper.methodType != MethodType.Boolean;
                Option option = new Option(shortName, longName, allowsArguments, description);

                // Configure it
                option.setRequired(commandLineOption.required());
                if (option.hasArg()) {
                    option.setType(helper.elementType);
                    option.setArgs(commandLineOption.maximumArgumentCount());
                    option.setValueSeparator(commandLineOption.argumentSeparator());
                    option.setOptionalArg(commandLineOption.optionalArgument());
                }

                // Remember it, both in the commons-cli options set and
                // in our list of elements for later post-processing
                options.addOption(option);
                optionHelperMap.put(option, helper);
            }

            // This was not a command line option method - is it the main command line method?
        } else if (method.isAnnotationPresent(CommandLineMain.class)) {

            // Make sure we only have one
            if (mainHelper != null) {
                throw new CommandLineException("Cannot have two main methods specified");
            } else {
                mainHelper = getHelperForCommandLineMain(method);
            }
        }
    }
}