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

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

Introduction

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

Prototype

public static OptionBuilder hasArg() 

Source Link

Document

The next Option created will require an argument value.

Usage

From source file:kina.testutils.ContextProperties.java

/**
 * Public constructor./* w  w w.  j a  v  a  2 s.  c  o m*/
 */
public ContextProperties(String[] args) {
    Options options = new Options();

    options.addOption("m", "master", true, "The spark's master endpoint");
    options.addOption("h", "sparkHome", true, "The spark's home, eg. /opt/spark");
    options.addOption("H", "cassandraHost", true, "Cassandra endpoint");

    options.addOption(OptionBuilder.hasArg().withType(Integer.class).withLongOpt("cassandraCqlPort")
            .withArgName("cassandra_cql_port").withDescription("cassandra's cql port, defaults to 9042")
            .create());
    options.addOption(OptionBuilder.hasArg().withType(Integer.class).withLongOpt("cassandraThriftPort")
            .withArgName("cassandra_thrift_port")
            .withDescription("cassandra's thrift port, " + "defaults to 9160").create());
    options.addOption(OptionBuilder.hasArg().withValueSeparator(',').withLongOpt("jars")
            .withArgName("jars_to_add").withDescription("comma separated list of jars to add").create());
    Option help = new Option("help", "print this message");
    //options.addOption("j","jars", true, "comma separated list of jars to add");
    options.addOption(help);
    CommandLineParser parser = new PosixParser();
    HelpFormatter formatter = new HelpFormatter();

    try {
        CommandLine line = parser.parse(options, args);

        if (line.hasOption("help")) {
            formatter.printHelp("", options);

            throw new GenericException("Help command issued");
        }

        jar = (line.hasOption("jars") ? line.getOptionValues("jars") : new String[] {});
        cluster = line.getOptionValue("master", defaultIfEmpty(System.getProperty("spark.master"), "local"));
        sparkHome = line.getOptionValue("sparkHome", defaultIfEmpty(System.getProperty("spark.home"), ""));
        cassandraHost = line.getOptionValue("cassandraHost", Constants.DEFAULT_CASSANDRA_HOST);
        cassandraCqlPort = line.hasOption("cassandraCqlPort")
                ? Integer.parseInt(line.getOptionValue("cassandraCqlPort"))
                : Constants.DEFAULT_CASSANDRA_CQL_PORT;
        cassandraThriftPort = line.hasOption("cassandraThriftPort")
                ? Integer.parseInt(line.getOptionValue("cassandraThriftPort"))
                : Constants.DEFAULT_CASSANDRA_RPC_PORT;

    } catch (ParseException e) {
        formatter.printHelp("", options);
        LOG.error("Unexpected exception: ", e);
    }
}

From source file:chibi.gemmaanalysis.CorrelationAnalysisCLI.java

@SuppressWarnings("static-access")
@Override/*from w ww . ja v  a2s  . c o  m*/
protected void buildOptions() {
    super.buildOptions();
    Option outputFileOption = OptionBuilder.hasArg().isRequired().withArgName("File prefix")
            .withDescription("File prefix for saving the output").withLongOpt("outFilePrefix").create('o');
    addOption(outputFileOption);

    Option kMaxOption = OptionBuilder.hasArg().withArgName("k").withDescription("Select the kth largest value")
            .withType(Integer.class).withLongOpt("kValue").create('k');
    addOption(kMaxOption);
}

From source file:net.alegen.datpass.cli.input.ProfileCommand.java

protected ProfileCommand() {
    this.options = new Options();
    Option list = OptionBuilder.withDescription("list all existing profiles").withLongOpt(OPTION_LIST_LONG)
            .create(OPTION_LIST);//w  w  w . j  a va2 s . c o  m
    Option create = OptionBuilder.withDescription("create a new profile").withLongOpt(OPTION_CREATE_LONG)
            .create(OPTION_CREATE);
    Option remove = OptionBuilder.hasArg().withArgName("name")
            .withDescription("remove an existing profile with the given name").withLongOpt(OPTION_REMOVE_LONG)
            .create(OPTION_REMOVE);
    Option unlock = OptionBuilder.hasArg().withArgName("name")
            .withDescription("unlock and load an existing profile with the given name")
            .withLongOpt(OPTION_UNLOCK_LONG).create(OPTION_UNLOCK);
    Option encrypted = OptionBuilder.withDescription("unlock and load an existing profile with the given name")
            .withLongOpt(OPTION_ENCRYPTED_LONG).create(OPTION_ENCRYPTED);
    this.options.addOption(list);
    this.options.addOption(create);
    this.options.addOption(remove);
    this.options.addOption(unlock);
    this.options.addOption(encrypted);
}

From source file:com.google.code.bing.search.example.AdSample.java

/**
 * Builds the options.//  ww w  . j av  a  2s  . c o m
 * 
 * @return the options
 */
private static Options buildOptions() {

    Options opts = new Options();

    String helpMsg = "Print this message.";
    Option help = new Option(HELP_OPTION, helpMsg);
    opts.addOption(help);

    String applicationKeyMsg = "You Application ID.";
    OptionBuilder.withArgName("appid");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(applicationKeyMsg);
    Option applicationKey = OptionBuilder.create(APPLICATION_KEY_OPTION);
    opts.addOption(applicationKey);

    String queryMsg = "Search Query.";
    OptionBuilder.withArgName("query");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(queryMsg);
    Option query = OptionBuilder.create(QUERY_OPTION);
    opts.addOption(query);

    return opts;
}

From source file:edu.harvard.med.lincs.screensaver.io.screens.ScreenAttachmentImporter.java

@SuppressWarnings("static-access")
public ScreenAttachmentImporter(String[] cmdLineArgs) {
    super(cmdLineArgs);

    String[] option = OPTION_INPUT_FILE;
    addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName(option[ARG_INDEX])
            .withDescription(option[DESCRIPTION_INDEX]).withLongOpt(option[LONG_OPTION_INDEX])
            .create(option[SHORT_OPTION_INDEX]));
    option = OPTION_INPUT_FACILITY_ID;/*from www. ja v  a 2 s  .  c om*/
    addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName(option[ARG_INDEX])
            .withDescription(option[DESCRIPTION_INDEX]).withLongOpt(option[LONG_OPTION_INDEX])
            .create(option[SHORT_OPTION_INDEX]));
    //    option = OPTION_ATTACHMENT_TYPE;
    //    addCommandLineOption(OptionBuilder.hasArg()
    //                             .isRequired()
    //                                          .withArgName(option[ARG_INDEX])
    //                                          .withDescription(option[DESCRIPTION_INDEX])
    //                                          .withLongOpt(option[LONG_OPTION_INDEX])
    //                                          .create(option[SHORT_OPTION_INDEX]));
}

From source file:de.clusteval.data.dataset.generator.CassiniDataSetGenerator.java

@Override
protected Options getOptions() {
    Options options = new Options();

    OptionBuilder.withArgName("n");
    OptionBuilder.isRequired();/*w w  w.ja  va2  s  .c  o m*/
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("The number of points.");
    Option option = OptionBuilder.create("n");
    options.addOption(option);

    return options;
}

From source file:com.stratio.deep.examples.utils.ContextProperties.java

/**
 * Public constructor.//www .  j  av  a 2 s.  c o m
 */
public ContextProperties(String[] args) {
    Options options = new Options();

    options.addOption("m", "master", true, "The spark's master endpoint");
    options.addOption("h", "sparkHome", true, "The spark's home, eg. /opt/spark");
    options.addOption("H", "cassandraHost", true, "Cassandra endpoint");

    options.addOption(OptionBuilder.hasArg().withType(Integer.class).withLongOpt("cassandraCqlPort")
            .withArgName("cassandra_cql_port").withDescription("cassandra's cql port, defaults to 9042")
            .create());
    options.addOption(OptionBuilder.hasArg().withType(Integer.class).withLongOpt("cassandraThriftPort")
            .withArgName("cassandra_thrift_port")
            .withDescription("cassandra's thrift port, " + "defaults to 9160").create());
    options.addOption(OptionBuilder.hasArg().withValueSeparator(',').withLongOpt("jars")
            .withArgName("jars_to_add").withDescription("comma separated list of jars to add").create());
    Option help = new Option("help", "print this message");
    //options.addOption("j","jars", true, "comma separated list of jars to add");
    options.addOption(help);
    CommandLineParser parser = new PosixParser();
    HelpFormatter formatter = new HelpFormatter();

    try {
        CommandLine line = parser.parse(options, args);

        if (line.hasOption("help")) {
            formatter.printHelp("", options);

            throw new DeepGenericException("Help command issued");
        }

        jar = (line.hasOption("jars") ? line.getOptionValues("jars") : new String[] {});
        cluster = line.getOptionValue("master", defaultIfEmpty(System.getProperty("spark.master"), "local"));
        sparkHome = line.getOptionValue("sparkHome", defaultIfEmpty(System.getProperty("spark.home"), ""));
        cassandraHost = line.getOptionValue("cassandraHost", Constants.DEFAULT_CASSANDRA_HOST);
        cassandraCqlPort = line.hasOption("cassandraCqlPort")
                ? Integer.parseInt(line.getOptionValue("cassandraCqlPort"))
                : Constants.DEFAULT_CASSANDRA_CQL_PORT;
        cassandraThriftPort = line.hasOption("cassandraThriftPort")
                ? Integer.parseInt(line.getOptionValue("cassandraThriftPort"))
                : Constants.DEFAULT_CASSANDRA_RPC_PORT;

    } catch (ParseException e) {
        formatter.printHelp("", options);
        LOG.error("Unexpected exception: ", e);
    }
}

From source file:de.clusteval.data.dataset.generator.CircleDataSetGenerator.java

@Override
protected Options getOptions() {
    Options options = new Options();

    OptionBuilder.withArgName("n");
    OptionBuilder.isRequired();/*from  ww  w  . jav  a 2 s  .c o  m*/
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("The number of points.");
    Option option = OptionBuilder.create("n");
    options.addOption(option);

    OptionBuilder.withArgName("d");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("The number of dimensions.");
    option = OptionBuilder.create("d");
    options.addOption(option);

    return options;
}

From source file:de.clusteval.data.dataset.generator.SpiralsDataSetGenerator.java

@Override
protected Options getOptions() {
    Options options = new Options();

    OptionBuilder.withArgName("n");
    OptionBuilder.isRequired();/*from   ww  w  .j av a  2  s . c o m*/
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("The number of points.");
    Option option = OptionBuilder.create("n");
    options.addOption(option);

    OptionBuilder.withArgName("c");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("The number of cycles.");
    option = OptionBuilder.create("c");
    options.addOption(option);

    OptionBuilder.withArgName("sd");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("The standard deviation.");
    option = OptionBuilder.create("sd");
    options.addOption(option);

    return options;
}

From source file:chibi.gemmaanalysis.ArrayDesignStatCli.java

@Override
@SuppressWarnings("static-access")
protected void buildOptions() {
    super.buildOptions();

    Option expOption = OptionBuilder.hasArg().withArgName("outfile").withDescription("TSV output filename")
            .withLongOpt("outfile").create('o');
    addOption(expOption);//  w w w. ja va  2  s. c  o m

    Option taxonOption = OptionBuilder.hasArg().withDescription("taxon name")
            .withDescription("Taxon of the expression experiments and genes").withLongOpt("taxon").create('t');
    addOption(taxonOption);
}