Example usage for org.apache.commons.cli OptionBuilder withLongOpt

List of usage examples for org.apache.commons.cli OptionBuilder withLongOpt

Introduction

In this page you can find the example usage for org.apache.commons.cli OptionBuilder withLongOpt.

Prototype

public static OptionBuilder withLongOpt(String newLongopt) 

Source Link

Document

The next Option created will have the following long option value.

Usage

From source file:com.amazonaws.example.CreateLinuxAmi.java

/**
 * Build a command line option object.// ww w .  java 2 s  . c o  m
 *
 * @param key the command line option name
 * @param description a description of what this option does
 * @param argName the argument value that is associated with the
 *                 option value; e.g. --foo=argName.
 *
 * @return a new Option object.
 */
private static Option buildOption(final String key, final String description, final String argName) {

    return OptionBuilder.withLongOpt(key).withDescription(description).hasArg().isRequired()
            .withArgName(argName).create();
}

From source file:com.eucalyptus.upgrade.TestHarness.java

@SuppressWarnings("static-access")
private static Options getCliOptions() {
    final Options opts = new Options();
    opts.addOption(OptionBuilder.withLongOpt("test").hasArgs().withDescription(
            "Run the specified test; this option can appear multiple times. Parameters can be set as key=value pairs. e.g. ConcurrencyTest:threads=16")
            .withArgName("TEST_CLASS[:PARAM=VALUE]*").create("t"));
    opts.addOption(OptionBuilder.withLongOpt(Opts.help.name()).withDescription("Show this help information.")
            .create("h"));
    return opts;/*from w  w w .  j  a v a  2s. c  o  m*/
}

From source file:com.eviware.loadui.launcher.LoadUICommandLineLauncher.java

@Override
@SuppressWarnings("static-access")
protected Options createOptions() {
    Options options = super.createOptions();
    options.addOption(WORKSPACE_OPTION, "workspace", true, "Sets the Workspace file to load");
    options.addOption(PROJECT_OPTION, "project", true, "Sets the Project file to run");
    options.addOption(TESTCASE_OPTION, "testcase", true,
            "Sets which TestCase to run (leave blank to run the entire Project)");
    options.addOption(VU_SCENARIO_OPTION, "scenario", true,
            "Sets which Scenario to run (leave blank to run the entire Project)");
    options.addOption(LIMITS_OPTION, "limits", true,
            "Sets the limits (<SECONDS>:<REQUESTS>:<FAILURES>) for the execution (e.g. -L 60:0:200 )");
    options.addOption(OptionBuilder
            .withLongOpt("agents").withDescription("Sets the agents to use for the test ( usage -"
                    + AGENT_OPTION + " <ip>[:<port>][=<scenario>[,<scenario>] ...] )")
            .hasArgs().create(AGENT_OPTION));
    options.addOption(FILE_OPTION, "file", true, "Executes the specified Groovy script file");
    options.addOption(LOCAL_OPTION, "local", false, "Executes TestCases in local mode");
    options.addOption(REPORT_DIR_OPTION, "reports", true,
            "Generates reports and saves them in specified folder");
    options.addOption(REPORT_FORMAT_OPTION, "format", true,
            "Specify output format for the exported reports (supported formats are: PDF, XLS, HTML, RTF, CSV, TXT and XML)");
    options.addOption(OptionBuilder.withLongOpt("statistics")
            .withDescription(/*from w w  w. j ava 2 s.  c om*/
                    "Sets which Statistics pages to add to the generated report (leave blank save all pages)")
            .hasOptionalArgs().create(STATISTICS_REPORT_OPTION));
    options.addOption(STATISTICS_REPORT_INCLUDE_SUMMARY_OPTION, "summary", false,
            "Set to include summary report in statistics report");
    options.addOption(STATISTICS_REPORT_COMPARE_OPTION, "compare", true,
            "Specify a saved execution to use as a base for comparison in the generated statistics report");
    options.addOption(ABORT_ONGOING_REQUESTS_OPTION, "abort", true,
            "Overrides \"Abort ongoing requests on finish\" project property. If set to true ongoing requests will be canceled, if false test will finish when all ongoing requests complete. If not set, property value from project will be used to determine what to do with ongoing requests.");

    options.addOption(RETAIN_SAVED_ZOOM_LEVELS, false,
            "Use the saved zoom levels for charts from the project.");

    return options;
}

From source file:com.rapplogic.aru.uploader.xbee.XBeeSketchUploader.java

private void runFromCmdLine(String[] args) throws org.apache.commons.cli.ParseException, IOException {
    CliOptions cliOptions = getCliOptions();

    cliOptions.addOption(OptionBuilder.withLongOpt(radioType).hasArg().isRequired(true)
            .withDescription("XBee radio series: must be either series1 or series2. Required").create("i"));

    cliOptions.addOption(OptionBuilder.withLongOpt(serialPort).hasArg().isRequired(true)
            .withDescription(/*from w w  w .  j a v  a 2s .c  o m*/
                    "Serial port of of local xbee (host) radio) (e.g. /dev/tty.usbserial-A6005uRz). Required")
            .create("p"));

    cliOptions.addOption(OptionBuilder.withLongOpt(baudRate).hasArg().isRequired(true).withType(Number.class)
            .withDescription("Baud rate of local xbee (host) radio serial port. Required").create("b"));

    cliOptions.addOption(OptionBuilder.withLongOpt(xbeeAddress).hasArg().isRequired(true)
            .withDescription("Address (64-bit) of remote XBee radio (e.g. 0013A21240AB9856)").create("x"));

    cliOptions.build();

    CommandLine commandLine = cliOptions.parse(args);

    if (commandLine != null) {

        // validate
        try {
            Series series = Series.valueOf(commandLine.getOptionValue(radioType).toUpperCase());
        } catch (Exception e) {
            System.err.println(radioType + " must be series1 or series2");
            return;
        }

        // cmd line
        new XBeeSketchUploader().flash(commandLine.getOptionValue(CliOptions.sketch),
                commandLine.getOptionValue(radioType), commandLine.getOptionValue(serialPort),
                cliOptions.getIntegerOption(baudRate), commandLine.getOptionValue(xbeeAddress),
                commandLine.hasOption(CliOptions.verboseArg),
                cliOptions.getIntegerOption(CliOptions.ackTimeoutMillisArg),
                cliOptions.getIntegerOption(CliOptions.arduinoTimeoutArg),
                cliOptions.getIntegerOption(CliOptions.retriesPerPacketArg),
                cliOptions.getIntegerOption(CliOptions.delayBetweenRetriesMillisArg));
    }
}

From source file:ca.uqac.info.Job.Launcher.JobLauncher.java

/**
 * Sets up the options for the command line parser
 * @return The options//from  www .jav  a 2 s.  c  om
 */
@SuppressWarnings("static-access")
private static Options setupOptions() {
    Options options = new Options();
    Option opt;
    opt = OptionBuilder.withLongOpt("help").withDescription("Display command line usage").create("h");
    options.addOption(opt);
    opt = OptionBuilder.withLongOpt("BatFolder").withArgName("x").hasArg()
            .withDescription("Folder who contain the bat files to execute").create("b");
    options.addOption(opt);
    opt = OptionBuilder.withLongOpt("OutputFolder").withArgName("x").hasArg()
            .withDescription("The output folder who contains the results").create("o");
    options.addOption(opt);
    opt = OptionBuilder.withLongOpt("username").withArgName("x").hasArg()
            .withDescription("Set the username of the email transmitter").create("u");
    options.addOption(opt);
    opt = OptionBuilder.withLongOpt("password").withArgName("x").hasArg()
            .withDescription("Set the password of the email transmitter").create("p");
    options.addOption(opt);
    opt = OptionBuilder.withLongOpt("recipientEmail").withArgName("x").hasArg()
            .withDescription("Set the email of the recipient").create("r");
    options.addOption(opt);
    opt = OptionBuilder.withLongOpt("email").withArgName("x").hasArg()
            .withDescription("Set the email option to action --> true").create("e");
    options.addOption(opt);

    return options;
}

From source file:com.ibm.watson.developer_cloud.professor_languo.ingestion.IngestionDriver.java

/**
 * create a CommandLine interpreter while is able to detect the options used by the user and get
 * the values of the options easily/*from  w  w w.j  a v a 2  s  . c o  m*/
 * 
 * @param args - the string tokens for the command line arguments
 * @return a CommandLine interpreter while is able to detect the options used by the user and get
 *         the values of the options easily
 * @throws IngestionException
 */
@SuppressWarnings("static-access")
private static CommandLine createCmdLineInterpreter(String[] args) throws IngestionException {
    CommandLine cmdLine = null;
    CommandLineParser parser = new BasicParser();

    options.addOption("h", "help", false, Messages.getString("RetrieveAndRank.CLI_DESCRIPTION_HELP")); //$NON-NLS-1$

    options.addOption(OptionBuilder.withLongOpt("indexStat").withArgName("index status file path").hasArg()
            .withDescription(Messages.getString("RetrieveAndRank.CLI_DESCRIPTION_INDEX_STAT")) //$NON-NLS-1$
            .create("i"));

    options.addOption(OptionBuilder.withLongOpt("queryGeneratorsStr").withArgName("query generators").hasArg()
            .withDescription(Messages.getString("RetrieveAndRank.CLI_DESCRIPTION_QUERY_GENERATORS")) //$NON-NLS-1$
            .create("q"));

    options.addOption(OptionBuilder.withLongOpt("indexDir").withArgName("index file directory path").hasArg()
            .withDescription(Messages.getString("RetrieveAndRank.CLI_DESCRIPTION_INDEX_DIR")) //$NON-NLS-1$
            .create("d"));

    options.addOption(OptionBuilder.withLongOpt("tsvDir").withArgName("duplicate thread file directory path")
            .hasArg().withDescription(Messages.getString("RetrieveAndRank.CLI_DESCRIPTION_TSV_DIR")) //$NON-NLS-1$
            .create("v"));

    options.addOption(OptionBuilder.withLongOpt("uniqDir").withArgName("unique thread file directory path")
            .hasArg().withDescription(Messages.getString("RetrieveAndRank.CLI_DESCRIPTION_UNIQUE_DIR")) //$NON-NLS-1$
            .create("u"));

    options.addOption(OptionBuilder.withLongOpt("resDir").withArgName(
            "The directory path for by products generated by the application(e.g. index file, stats, csv file for dupthreads)")
            .hasArg().withDescription(Messages.getString("RetrieveAndRank.CLI_DESCRIPTION_RES_DIR")) //$NON-NLS-1$
            .create("r"));

    options.addOption(OptionBuilder.withLongOpt("caAnswerNum")
            .withArgName("The number of candidate answers returned by the candidate answer generator").hasArg()
            .withDescription(Messages.getString("RetrieveAndRank.CLI_DESCRIPTION_CANDIDATE_ANSWER_NUM")) //$NON-NLS-1$
            .create("b"));

    options.addOption(OptionBuilder.isRequired().withLongOpt("configure").withArgName("configuration file name")
            .hasArg().withDescription(Messages.getString("RetrieveAndRank.CLI_DESCRIPTION_CONFIGURE")) //$NON-NLS-1$
            .create("c"));
    try {
        cmdLine = parser.parse(options, args);
    } catch (ParseException e) {
        throw new IngestionException(e);
    }

    return cmdLine;
}

From source file:com.linkedin.databus.bootstrap.utils.BootstrapSeederMain.java

@SuppressWarnings("static-access")
public static void parseArgs(String[] args) throws IOException {
    CommandLineParser cliParser = new GnuParser();

    Option helpOption = OptionBuilder.withLongOpt(HELP_OPT_LONG_NAME).withDescription("Help screen")
            .create(HELP_OPT_CHAR);/* w  ww  . j a va2s  .  c o  m*/

    Option sourcesOption = OptionBuilder.withLongOpt(PHYSICAL_CONFIG_OPT_LONG_NAME)
            .withDescription("Bootstrap producer properties to use").hasArg().withArgName("property_file")
            .create(PHYSICAL_CONFIG_OPT_CHAR);

    Option dbOption = OptionBuilder.withLongOpt(BOOTSTRAP_DB_PROPS_OPT_LONG_NAME)
            .withDescription("Bootstrap producer properties to use").hasArg().withArgName("property_file")
            .create(BOOTSTRAP_DB_PROP_OPT_CHAR);

    Option log4jPropsOption = OptionBuilder.withLongOpt(LOG4J_PROPS_OPT_LONG_NAME)
            .withDescription("Log4j properties to use").hasArg().withArgName("property_file")
            .create(LOG4J_PROPS_OPT_CHAR);

    Option validationType = OptionBuilder.withLongOpt(VALIDATION_TYPE_OPT_LONG_NAME).withDescription(
            "Type of validation algorithm , normal[cmp two sorted streams of oracle and bootstrap db]  or point[entry in bootstrap checked in oracle]")
            .hasArg().withArgName("validation_type").create(VALIDATION_TYPE_OPT_CHAR);

    Option validationSamplePct = OptionBuilder.withLongOpt(VALIDATION_SAMPLE_PCT_LONG_NAME)
            .withDescription("Validation sample pct ,0.0 to 100.00 [100.0]").hasArg()
            .withArgName("validation_sample_pct").create(VALIDATION_SAMPLE_PCT_CHAR);

    Options options = new Options();
    options.addOption(helpOption);
    options.addOption(sourcesOption);
    options.addOption(dbOption);
    options.addOption(log4jPropsOption);
    options.addOption(validationType);
    options.addOption(validationSamplePct);

    CommandLine cmd = null;
    try {
        cmd = cliParser.parse(options, args);
    } catch (ParseException pe) {
        LOG.fatal("Bootstrap Physical Config: failed to parse command-line options.", pe);
        throw new RuntimeException("Bootstrap Physical Config: failed to parse command-line options.", pe);
    }

    if (cmd.hasOption(LOG4J_PROPS_OPT_CHAR)) {
        String log4jPropFile = cmd.getOptionValue(LOG4J_PROPS_OPT_CHAR);
        PropertyConfigurator.configure(log4jPropFile);
        LOG.info("Using custom logging settings from file " + log4jPropFile);
    } else {
        PatternLayout defaultLayout = new PatternLayout("%d{ISO8601} +%r [%t] (%p) {%c} %m%n");
        ConsoleAppender defaultAppender = new ConsoleAppender(defaultLayout);

        Logger.getRootLogger().removeAllAppenders();
        Logger.getRootLogger().addAppender(defaultAppender);
        Logger.getRootLogger().setLevel(Level.INFO); //using info as the default log level
        LOG.info("Using default logging settings. Log Level is :" + Logger.getRootLogger().getLevel());
    }

    if (cmd.hasOption(HELP_OPT_CHAR)) {
        printCliHelp(options);
        System.exit(0);
    }

    if (!cmd.hasOption(PHYSICAL_CONFIG_OPT_CHAR))
        throw new RuntimeException("Sources Config is not provided; use --help for usage");

    if (!cmd.hasOption(BOOTSTRAP_DB_PROP_OPT_CHAR))
        throw new RuntimeException("Bootstrap config is not provided; use --help for usage");

    _sSourcesConfigFile = cmd.getOptionValue(PHYSICAL_CONFIG_OPT_CHAR);

    String propFile = cmd.getOptionValue(BOOTSTRAP_DB_PROP_OPT_CHAR);
    LOG.info("Loading bootstrap DB config from properties file " + propFile);

    _sBootstrapConfigProps = new Properties();
    _sBootstrapConfigProps.load(new FileInputStream(propFile));
    if (!cmd.hasOption(VALIDATION_TYPE_OPT_CHAR)) {
        _validationType = "normal";
    } else {
        String vtype = cmd.getOptionValue(VALIDATION_TYPE_OPT_CHAR);
        if (vtype.equals("point") || vtype.equals("normal") || vtype.equals("pointBs")) {
            _validationType = vtype;
        } else {
            throw new RuntimeException("Validation type has to be one of 'normal' or 'point' or 'pointBs'");
        }
    }
    if (cmd.hasOption(VALIDATION_SAMPLE_PCT_CHAR)) {
        try {
            _validationSamplePct = Double.parseDouble(cmd.getOptionValue(VALIDATION_SAMPLE_PCT_CHAR));
            if (_validationSamplePct < 0.0 || _validationSamplePct > 100.0) {
                throw new RuntimeException("Error in specifying: " + VALIDATION_SAMPLE_PCT_LONG_NAME
                        + "Should be between 0.0 and 100.0. It was " + _validationSamplePct);
            }
        } catch (NumberFormatException e) {
            throw new RuntimeException(
                    "Error in specifying: " + VALIDATION_SAMPLE_PCT_LONG_NAME + " Exception:" + e);
        }
    } else {
        _validationSamplePct = 100.0;
    }

}

From source file:com.sshtools.appframework.ui.SshToolsApplication.java

/**
 * Add any required command line options to be passed to the Options object
 * supplied as an argument. Concrete Applications should overidde this, call
 * super.buildCLIOptions() then add any other options they might require.
 * /*from w  w  w. ja v  a  2s . c o m*/
 * @param options
 *            Options list to add option too
 */
public void buildCLIOptions(Options options) {
    OptionBuilder.withLongOpt("help");
    OptionBuilder.withDescription("show this help");
    Option help = OptionBuilder.create("?");
    options.addOption(help);
    if (isReuseCapable()) {
        OptionBuilder.withLongOpt("nodaemon");
        OptionBuilder.withDescription("do not start the instance re-use daemon");
        Option noListen = OptionBuilder.create("d");
        options.addOption(noListen);
    }
    OptionBuilder.withLongOpt("--reusePort");
    OptionBuilder.withArgName("port");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("port on which to listen for re-use requests");
    OptionBuilder.create("r");
    options.addOption("e", "noOptionsAction", false, "dont allow the user to change options.");
}

From source file:eu.crydee.alignment.aligner.VideoLecturesP.java

static private Params parseArguments(String[] args) throws ParseException {
    Options shortCircuitOptions = new Options();
    shortCircuitOptions/* w  w w . j  av  a2s  .c  o  m*/
            .addOption(OptionBuilder.withLongOpt("help").withDescription("Print this message.").create('h'));
    shortCircuitOptions
            .addOption(OptionBuilder.withLongOpt("version").withDescription("Print the version.").create('v'));
    Options options = new Options();
    options.addOption(OptionBuilder.isRequired().withLongOpt("tei").hasArg().withArgName("folder-path")
            .withDescription("Path to the folder of the TEI body files.").create('t'));
    options.addOption(OptionBuilder.isRequired().withLongOpt("dfxp").hasArg().withArgName("folder-path")
            .withDescription("Path to the folder of the DFXP files.").create('d'));
    CommandLineParser parser = new PosixParser();
    CommandLine cmd = parser.parse(shortCircuitOptions, args, true);
    if (cmd.hasOption('h')) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("aligner", options, true);
        System.exit(0);
    }
    if (cmd.hasOption('v')) {
        System.out.println("aligner v1.0.0-SNAPSHOT");
        System.exit(0);
    }
    cmd = parser.parse(options, args);
    return new Params(cmd.getOptionValue('t'), cmd.getOptionValue('d'));
}

From source file:com.facebook.presto.accumulo.examples.TpcHClerkSearch.java

@Override
public Options getOptions() {
    Options opts = new Options();
    opts.addOption(OptionBuilder.withLongOpt("clerk-id")
            .withDescription("List of Clerk IDs to search for orders").hasArgs().isRequired().create(CLERK_ID));
    return opts;/*from w ww. jav a2  s .c  o  m*/
}