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

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

Introduction

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

Prototype

public static OptionBuilder withArgName(String name) 

Source Link

Document

The next Option created will have the specified argument value name.

Usage

From source file:com.netflix.Aegisthus.java

@SuppressWarnings("static-access")
public CommandLine getOptions(String[] args) {
    Options opts = new Options();
    opts.addOption(OptionBuilder.withArgName(OPT_INPUT).withDescription("Each input location").hasArgs()
            .create(OPT_INPUT));//from  ww w  . j a  va2  s. c  o  m
    opts.addOption(OptionBuilder.withArgName(OPT_OUTPUT).isRequired().withDescription("output location")
            .hasArg().create(OPT_OUTPUT));
    opts.addOption(OptionBuilder.withArgName(OPT_INPUTDIR)
            .withDescription("a directory from which we will recursively pull sstables").hasArgs()
            .create(OPT_INPUTDIR));
    CommandLineParser parser = new GnuParser();

    try {
        CommandLine cl = parser.parse(opts, args, true);
        if (!(cl.hasOption(OPT_INPUT) || cl.hasOption(OPT_INPUTDIR))) {
            System.out.println("Must have either an input or inputDir option");
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp(String.format("hadoop jar aegsithus.jar %s", Aegisthus.class.getName()), opts);
            return null;
        }
        return cl;
    } catch (ParseException e) {
        System.out.println("Unexpected exception:" + e.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(String.format("hadoop jar aegisthus.jar %s", Aegisthus.class.getName()), opts);
        return null;
    }

}

From source file:com.google.code.linkedinapi.client.examples.PostStatusExample.java

/**
  * Build command line options object.//from w ww .j ava2  s  . co  m
  */
private static Options buildOptions() {

    Options opts = new Options();

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

    String consumerKeyMsg = "You API Consumer Key.";
    OptionBuilder.withArgName("consumerKey");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(consumerKeyMsg);
    Option consumerKey = OptionBuilder.create(CONSUMER_KEY_OPTION);
    opts.addOption(consumerKey);

    String consumerSecretMsg = "You API Consumer Secret.";
    OptionBuilder.withArgName("consumerSecret");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(consumerSecretMsg);
    Option consumerSecret = OptionBuilder.create(CONSUMER_SECRET_OPTION);
    opts.addOption(consumerSecret);

    String accessTokenMsg = "You OAuth Access Token.";
    OptionBuilder.withArgName("accessToken");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(accessTokenMsg);
    Option accessToken = OptionBuilder.create(ACCESS_TOKEN_OPTION);
    opts.addOption(accessToken);

    String tokenSecretMsg = "You OAuth Access Token Secret.";
    OptionBuilder.withArgName("accessTokenSecret");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(tokenSecretMsg);
    Option accessTokenSecret = OptionBuilder.create(ACCESS_TOKEN_SECRET_OPTION);
    opts.addOption(accessTokenSecret);

    String statusMsg = "Text of the status.";
    OptionBuilder.withArgName("status");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(statusMsg);
    Option status = OptionBuilder.create(STATUS_TEXT_OPTION);
    opts.addOption(status);

    String deleteMsg = "Delete current status.";
    Option delete = new Option(DELETE_OPTION, deleteMsg);
    opts.addOption(delete);

    return opts;
}

From source file:mitm.common.tools.PfxTool.java

@SuppressWarnings("static-access")
private Options createCommandLineOptions() {
    Options options = new Options();

    inPasswordOption = OptionBuilder.withArgName("inpass").hasArg()
            .withDescription("Password for the input pfx.").create("inpass");
    inPasswordOption.setRequired(true);//ww  w .  j av a  2  s. co  m
    options.addOption(inPasswordOption);

    destPasswordOption = OptionBuilder.withArgName("destpass").hasArg()
            .withDescription("Password for the destination pfx.").create("destpass");
    destPasswordOption.setRequired(false);
    options.addOption(destPasswordOption);

    inOption = OptionBuilder.withArgName("file").hasArg().withDescription("The filename of the input pfx.")
            .create("in");
    inOption.setRequired(true);
    options.addOption(inOption);

    destOption = OptionBuilder.withArgName("file").hasArg()
            .withDescription("The filename of the destination pfx.").create("dest");
    destOption.setRequired(false);
    options.addOption(destOption);

    mergeOption = OptionBuilder.withDescription("Adds the input pfx to the output pfx.").create("merge");
    mergeOption.setRequired(false);
    options.addOption(mergeOption);

    listOption = OptionBuilder.withDescription("Shows all items from the input pfx.").create("list");
    listOption.setRequired(false);
    options.addOption(listOption);

    helpOption = OptionBuilder.withDescription("Show help").create("help");
    helpOption.setRequired(false);
    options.addOption(helpOption);

    retainAliasesOption = OptionBuilder.withDescription("If enabled, the aliases from the input will be kept.")
            .create("retainaliases");
    retainAliasesOption.setRequired(false);
    options.addOption(retainAliasesOption);

    return options;
}

From source file:ca.uqac.info.trace.generation.FsmGenerator.java

@SuppressWarnings("static-access")
@Override//www  .j a  v a 2s  .  co  m
public Options getCommandLineOptions() {
    Options options = super.getCommandLineOptions();
    Option opt;
    opt = OptionBuilder.withArgName("x").hasArg()
            .withDescription("Set finite-state machine to x (surrounded by quotes)").create("f");
    options.addOption(opt);
    return options;
}

From source file:com.google.code.uclassify.client.examples.TrainExample.java

/**
 * Build command line options object./*from  w ww. j  a v  a2s .  com*/
 * 
 * @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 consumerKeyMsg = "You API Write Key.";
    OptionBuilder.withArgName("readKey");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(consumerKeyMsg);
    Option consumerKey = OptionBuilder.create(WRITE_KEY);
    opts.addOption(consumerKey);

    String idMsg = "Classifier Name";
    OptionBuilder.withArgName("classifier");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(idMsg);
    Option id = OptionBuilder.create(CLASSIFIER);
    opts.addOption(id);

    String urlMsg = "Text to be classified.";
    OptionBuilder.withArgName("text");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(urlMsg);
    Option url = OptionBuilder.create(TEXT);
    opts.addOption(url);

    return opts;
}

From source file:io.bfscan.clueweb12.ProcessVByteDocVectors.java

/**
 * Runs this tool./*from w  w w . j a  v  a  2  s .  co m*/
 */
@SuppressWarnings("static-access")
public int run(String[] args) throws Exception {
    Options options = new Options();

    options.addOption(
            OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT_OPTION));
    options.addOption(
            OptionBuilder.withArgName("path").hasArg().withDescription("output path").create(OUTPUT_OPTION));
    options.addOption(
            OptionBuilder.withArgName("path").hasArg().withDescription("dictionary").create(DICTIONARY_OPTION));

    CommandLine cmdline;
    CommandLineParser parser = new GnuParser();
    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(this.getClass().getName(), options);
        ToolRunner.printGenericCommandUsage(System.out);
        System.err.println("Error parsing command line: " + exp.getMessage());
        return -1;
    }

    if (!cmdline.hasOption(INPUT_OPTION) || !cmdline.hasOption(OUTPUT_OPTION)
            || !cmdline.hasOption(DICTIONARY_OPTION)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(this.getClass().getName(), options);
        ToolRunner.printGenericCommandUsage(System.out);
        return -1;
    }

    String input = cmdline.getOptionValue(INPUT_OPTION);
    String output = cmdline.getOptionValue(OUTPUT_OPTION);
    String dictionary = cmdline.getOptionValue(DICTIONARY_OPTION);

    LOG.info("Tool name: " + ProcessVByteDocVectors.class.getSimpleName());
    LOG.info(" - input: " + input);
    LOG.info(" - output: " + output);
    LOG.info(" - dictionary: " + dictionary);

    Job job = new Job(getConf(), ProcessVByteDocVectors.class.getSimpleName() + ":" + input);
    job.setJarByClass(ProcessVByteDocVectors.class);

    job.setNumReduceTasks(0);

    FileInputFormat.setInputPaths(job, input);
    FileOutputFormat.setOutputPath(job, new Path(output));

    job.getConfiguration().set(DICTIONARY_OPTION, dictionary);

    job.setInputFormatClass(SequenceFileInputFormat.class);
    job.setOutputFormatClass(TextOutputFormat.class);

    job.setMapOutputKeyClass(Text.class);
    job.setMapOutputValueClass(Text.class);

    job.setMapperClass(MyMapper.class);

    FileSystem.get(getConf()).delete(new Path(output), true);

    long startTime = System.currentTimeMillis();
    job.waitForCompletion(true);
    LOG.info("Job Finished in " + (System.currentTimeMillis() - startTime) / 1000.0 + " seconds");

    return 0;
}

From source file:io.bfscan.clueweb12.ProcessPForDocVectors.java

/**
 * Runs this tool./* w ww. ja  v a  2  s .com*/
 */
@SuppressWarnings("static-access")
public int run(String[] args) throws Exception {
    Options options = new Options();

    options.addOption(
            OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT_OPTION));
    options.addOption(
            OptionBuilder.withArgName("path").hasArg().withDescription("output path").create(OUTPUT_OPTION));
    options.addOption(
            OptionBuilder.withArgName("path").hasArg().withDescription("dictionary").create(DICTIONARY_OPTION));

    CommandLine cmdline;
    CommandLineParser parser = new GnuParser();
    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(this.getClass().getName(), options);
        ToolRunner.printGenericCommandUsage(System.out);
        System.err.println("Error parsing command line: " + exp.getMessage());
        return -1;
    }

    if (!cmdline.hasOption(INPUT_OPTION) || !cmdline.hasOption(OUTPUT_OPTION)
            || !cmdline.hasOption(DICTIONARY_OPTION)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(this.getClass().getName(), options);
        ToolRunner.printGenericCommandUsage(System.out);
        return -1;
    }

    String input = cmdline.getOptionValue(INPUT_OPTION);
    String output = cmdline.getOptionValue(OUTPUT_OPTION);
    String dictionary = cmdline.getOptionValue(DICTIONARY_OPTION);

    LOG.info("Tool name: " + ProcessPForDocVectors.class.getSimpleName());
    LOG.info(" - input: " + input);
    LOG.info(" - output: " + output);
    LOG.info(" - dictionary: " + dictionary);

    Job job = new Job(getConf(), ProcessPForDocVectors.class.getSimpleName() + ":" + input);
    job.setJarByClass(ProcessPForDocVectors.class);

    job.setNumReduceTasks(0);

    FileInputFormat.setInputPaths(job, input);
    FileOutputFormat.setOutputPath(job, new Path(output));

    job.getConfiguration().set(DICTIONARY_OPTION, dictionary);

    job.setInputFormatClass(SequenceFileInputFormat.class);
    job.setOutputFormatClass(TextOutputFormat.class);

    job.setMapOutputKeyClass(Text.class);
    job.setMapOutputValueClass(Text.class);

    job.setMapperClass(MyMapper.class);

    FileSystem.get(getConf()).delete(new Path(output), true);

    long startTime = System.currentTimeMillis();
    job.waitForCompletion(true);
    LOG.info("Job Finished in " + (System.currentTimeMillis() - startTime) / 1000.0 + " seconds");

    return 0;
}

From source file:com.ricston.akka.matrix.Main.java

@SuppressWarnings("static-access")
private static void setUpCLOptions(Options options) {
    Option generateOpt = OptionBuilder.withArgName(GENERATE_ARGS).hasArgs(5)
            .withDescription(GENERATE_DESCRIPTION).withValueSeparator(',').create(GENERATE);
    Option computeOpt = OptionBuilder.withArgName(COMPUTE_ARG).hasArgs().withDescription(COMPUTE_DESCRIPTION)
            .withValueSeparator(':').create(COMPUTE);
    Option actorOpt = OptionBuilder.withArgName(ACTORS_ARG).hasArg().withDescription(ACTORS_DESCRIPTION)
            .create(ACTORS);/*from www  . j  a v a2 s  .c  o  m*/

    options.addOption(generateOpt);
    options.addOption(computeOpt);
    options.addOption(actorOpt);
}

From source file:com.google.code.linkedinapi.client.examples.PostNetworkUpdateExample.java

/**
  * Build command line options object.//  w w w  . j av a  2s  .c om
  */
private static Options buildOptions() {

    Options opts = new Options();

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

    String consumerKeyMsg = "You API Consumer Key.";
    OptionBuilder.withArgName("consumerKey");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(consumerKeyMsg);
    Option consumerKey = OptionBuilder.create(CONSUMER_KEY_OPTION);
    opts.addOption(consumerKey);

    String consumerSecretMsg = "You API Consumer Secret.";
    OptionBuilder.withArgName("consumerSecret");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(consumerSecretMsg);
    Option consumerSecret = OptionBuilder.create(CONSUMER_SECRET_OPTION);
    opts.addOption(consumerSecret);

    String accessTokenMsg = "You OAuth Access Token.";
    OptionBuilder.withArgName("accessToken");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(accessTokenMsg);
    Option accessToken = OptionBuilder.create(ACCESS_TOKEN_OPTION);
    opts.addOption(accessToken);

    String tokenSecretMsg = "You OAuth Access Token Secret.";
    OptionBuilder.withArgName("accessTokenSecret");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(tokenSecretMsg);
    Option accessTokenSecret = OptionBuilder.create(ACCESS_TOKEN_SECRET_OPTION);
    opts.addOption(accessTokenSecret);

    String updateMsg = "Text of the update.";
    OptionBuilder.withArgName("update");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(updateMsg);
    Option update = OptionBuilder.create(UPDATE_TEXT_OPTION);
    opts.addOption(update);

    return opts;
}

From source file:com.example.geomesa.transformations.QueryTutorial.java

/**
 * Main entry point. Executes queries against an existing GDELT dataset.
 *
 * @param args//from  w  w w  . j  ava  2  s  .  co m
 *
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    // read command line options - this contains the connection to accumulo and the table to query
    CommandLineParser parser = new BasicParser();
    Options options = SetupUtil.getCommonRequiredOptions();
    options.addOption(OptionBuilder.withArgName(FEATURE_NAME_ARG).hasArg().isRequired()
            .withDescription("the FeatureTypeName used to store the GDELT data, e.g.:  gdelt")
            .create(FEATURE_NAME_ARG));
    CommandLine cmd = parser.parse(options, args);

    // verify that we can see this Accumulo destination in a GeoTools manner
    Map<String, String> dsConf = SetupUtil.getAccumuloDataStoreConf(cmd);
    //Disable states collection
    dsConf.put("collectStats", "false");
    DataStore dataStore = DataStoreFinder.getDataStore(dsConf);
    assert dataStore != null;

    // create the simple feature type for our test
    String simpleFeatureTypeName = cmd.getOptionValue(FEATURE_NAME_ARG);
    SimpleFeatureType simpleFeatureType = GdeltFeature.buildGdeltFeatureType(simpleFeatureTypeName);

    // get the feature store used to query the GeoMesa data
    FeatureStore featureStore = (FeatureStore) dataStore.getFeatureSource(simpleFeatureTypeName);

    // execute some queries
    basicQuery(simpleFeatureTypeName, featureStore);
    basicProjectionQuery(simpleFeatureTypeName, featureStore);
    basicTransformationQuery(simpleFeatureTypeName, featureStore);
    renamedTransformationQuery(simpleFeatureTypeName, featureStore);
    mutliFieldTransformationQuery(simpleFeatureTypeName, featureStore);
    geometricTransformationQuery(simpleFeatureTypeName, featureStore);

    // the list of available transform functions is available here:
    // http://docs.geotools.org/latest/userguide/library/main/filter.html - scroll to 'Function List'
}