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:ComputeCooccurrenceMatrixPairs.java

/**
 * Runs this tool./*from www.  ja v  a2s.c o  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));
    options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("output path").create(OUTPUT));
    options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("window size").create(WINDOW));
    options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("number of reducers")
            .create(NUM_REDUCERS));

    CommandLine cmdline;
    CommandLineParser parser = new GnuParser();

    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Error parsing command line: " + exp.getMessage());
        return -1;
    }

    if (!cmdline.hasOption(INPUT) || !cmdline.hasOption(OUTPUT)) {
        System.out.println("args: " + Arrays.toString(args));
        HelpFormatter formatter = new HelpFormatter();
        formatter.setWidth(120);
        formatter.printHelp(this.getClass().getName(), options);
        ToolRunner.printGenericCommandUsage(System.out);
        return -1;
    }

    String inputPath = cmdline.getOptionValue(INPUT);
    String outputPath = cmdline.getOptionValue(OUTPUT);
    int reduceTasks = cmdline.hasOption(NUM_REDUCERS) ? Integer.parseInt(cmdline.getOptionValue(NUM_REDUCERS))
            : 1;
    int window = cmdline.hasOption(WINDOW) ? Integer.parseInt(cmdline.getOptionValue(WINDOW)) : 2;

    LOG.info("Tool: " + ComputeCooccurrenceMatrixPairs.class.getSimpleName());
    LOG.info(" - input path: " + inputPath);
    LOG.info(" - output path: " + outputPath);
    LOG.info(" - window: " + window);
    LOG.info(" - number of reducers: " + reduceTasks);

    Job job = Job.getInstance(getConf());
    job.setJobName(ComputeCooccurrenceMatrixPairs.class.getSimpleName());
    job.setJarByClass(ComputeCooccurrenceMatrixPairs.class);

    // Delete the output directory if it exists already.
    Path outputDir = new Path(outputPath);
    FileSystem.get(getConf()).delete(outputDir, true);

    job.getConfiguration().setInt("window", window);

    job.setNumReduceTasks(reduceTasks);

    FileInputFormat.setInputPaths(job, new Path(inputPath));
    FileOutputFormat.setOutputPath(job, new Path(outputPath));

    job.setMapOutputKeyClass(PairOfStrings.class);
    job.setMapOutputValueClass(IntWritable.class);
    job.setOutputKeyClass(PairOfStrings.class);
    job.setOutputValueClass(IntWritable.class);

    job.setMapperClass(MyMapper.class);
    job.setCombinerClass(MyReducer.class);
    job.setReducerClass(MyReducer.class);
    job.setPartitionerClass(MyPartitioner.class);

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

    return 0;
}

From source file:mitm.application.djigzo.tools.Monitor.java

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

    userOption = OptionBuilder.withArgName("user").hasArg().withDescription("user").create("user");
    userOption.setRequired(false);//from  w  ww.j a  v  a  2  s .  co  m
    options.addOption(userOption);

    passwordOption = OptionBuilder.withArgName("password").hasArg().withDescription("password")
            .create("password");
    passwordOption.setRequired(false);
    options.addOption(passwordOption);

    passwordPromptOption = OptionBuilder.withDescription("ask for password").create("pwd");
    passwordPromptOption.setRequired(false);
    options.addOption(passwordPromptOption);

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

    mpaSizeOption = OptionBuilder.withArgName("repository").hasArg()
            .withDescription("Returns the MPA mail queue size of [error, outgoing, spool, respool]")
            .create("mpasize");
    mpaSizeOption.setRequired(false);
    options.addOption(mpaSizeOption);

    crlStoreSizeOption = OptionBuilder.withDescription("Returns the size of the CRL store").create("crlsize");
    crlStoreSizeOption.setRequired(false);
    options.addOption(crlStoreSizeOption);

    runningOption = OptionBuilder.withDescription("Returns true if the back-end is running.").create("running");
    options.addOption(runningOption);

    mtaSizeOption = OptionBuilder.withDescription("Returns the MTA mail queue size").create("mtasize");
    options.addOption(mtaSizeOption);

    certStoreSizeOption = OptionBuilder.withDescription("Returns the certificate store size")
            .create("certsize");
    options.addOption(certStoreSizeOption);

    certRequestStoreSizeOption = OptionBuilder.withDescription("Returns the certificate request store size")
            .create("certrequestsize");
    options.addOption(certRequestStoreSizeOption);

    smsSizeOption = OptionBuilder.withDescription("Returns the SMS queue size").create("smssize");
    options.addOption(smsSizeOption);

    userSizeOption = OptionBuilder.withDescription("Returns the number of users").create("usersize");
    options.addOption(userSizeOption);

    loggingOption = OptionBuilder.withDescription("If set, debug logging will be enabled").create("logging");
    options.addOption(loggingOption);

    hostOption = OptionBuilder.withArgName("host").hasArg()
            .withDescription("The host to connect to (def: 127.0.0.1)").create("host");
    options.addOption(hostOption);

    portOption = OptionBuilder.withArgName("port").hasArg()
            .withDescription("The port to use (def: " + DjigzoWSDefaults.PORT + ")").create("port");
    options.addOption(portOption);

    return options;
}

From source file:com.archivas.clienttools.arcmover.cli.ArcMetadata.java

@SuppressWarnings({ "static-access", "AccessStaticViaInstance" })
public Options getOptions() {
    if (cliOptions == null) {
        Options options = new Options();

        // *** Adding a new option needs to be added to the cliOrder list
        // Note, you cannot do required options with this library and help so we have to add all
        // as non-required
        // and deal with it when parsing
        options.addOption(OptionBuilder.withDescription("Displays this help text (the default behavior).")
                .withLongOpt(HELP_OPTION).create("h"));

        // Required
        options.addOption(OptionBuilder.withArgName("profile_name").hasArg()
                .withDescription("Target location for the set metadata operation: a namespace profile name.")
                .withLongOpt(PROFILE_OPTION).create("p"));
        options.addOption(OptionBuilder.withArgName("path").hasArg()
                .withDescription("Directory in which to perform the set metadata operation.")
                .withLongOpt(PATH_OPTION).create());

        // Optional
        options.addOption(OptionBuilder.withArgName("path").hasArg()
                .withDescription("Custom metadata path.  Can be relative or absolute.")
                .withLongOpt(CUSTOM_METADATA_OPTION).create());

        options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription(
                "ACL path.  Can be relative or absolute.  This option only applies when updating a HCP 5.0 or later namespace.")
                .withLongOpt(ACL_OPTION).create());

        options.addOption(OptionBuilder.withArgName("path").hasArg()
                .withDescription(/*from  w ww  . j a va2 s. co  m*/
                        "Owner's name.  This option applies only when updating a HCP 5.0 or later namespace.")
                .withLongOpt(OWNER_OPTION).create());

        options.addOption(OptionBuilder.withArgName("path").hasArg()
                .withDescription(
                        "Owner's domain.  This option applies only when updating a HCP 5.0 or later namespace.")
                .withLongOpt(DOMAIN_OPTION).create());

        options.addOption(OptionBuilder.withArgName("true|false").hasArg()
                .withDescription("Specifies whether copied objects should be marked for indexing.")
                .withLongOpt(INDEX_OPTION).create());
        options.addOption(OptionBuilder.withArgName("true|false").hasArg()
                .withDescription("Specifies whether copied objects should be marked for shredding.")
                .withLongOpt(SHRED_OPTION).create());
        options.addOption(OptionBuilder.withArgName("true|false").hasArg()
                .withDescription("Specifies whether objects should be placed on hold.").withLongOpt(HOLD_OPTION)
                .create());
        options.addOption(OptionBuilder.withArgName("retention_setting").hasArg()
                .withDescription("Retention setting for copied objects.").withLongOpt(RETENTION_OPTION)
                .create());
        options.addOption(OptionBuilder.withArgName("job_name").hasOptionalArg().withDescription(
                "Reruns the metadata job with the given job name if provided; if no name is provided it reruns the last metadata job run.  When rerunning you can change the load and export settings.  Any changes to profiles, paths or metadata values will not change what is set in the job.")
                .withLongOpt(RERUN).create());
        options.addOption(OptionBuilder.withArgName("job_name").hasOptionalArg().withDescription(
                "Resumes the metadata job from where it left off, if no name is provided it resumes the last metadata job run.  When rerunning you can change the load and export settings.  Any changes to profiles, paths or metadata values will not change what is set in the job.")
                .withLongOpt(RESUME).create());
        options.addOption(OptionBuilder.withArgName("results_types").hasArg().withDescription(
                "Types of results lists to export: either ALL or a comma-separated list that includes one or more of SUCCESS, FAILURE, and JOBLIST.  If omitted no results lists are exported.")
                .withLongOpt(EXPORT_RESULTS_TYPE).create());
        getSharedOptions(options);

        cliOptions = options;
    }
    return cliOptions;
}

From source file:chibi.gemmaanalysis.GeneExpressionWriterCLI.java

@SuppressWarnings("static-access")
@Override//ww w  .  java2s. c  o m
protected void buildOptions() {
    super.buildOptions();

    addForceOption(null);

    OptionBuilder.hasArg();
    OptionBuilder.withDescription("Query file containing list of gene official symbols");
    OptionBuilder.withArgName("File name");
    OptionBuilder.withLongOpt("queryGeneFile");
    Option queryGeneFileOption = OptionBuilder.create();
    addOption(queryGeneFileOption);
    OptionBuilder.hasArgs();
    OptionBuilder.withArgName("Gene symbol(s)");
    OptionBuilder.withDescription("The query gene symbol(s), comma separated");
    OptionBuilder.withValueSeparator(',');
    OptionBuilder.withLongOpt("queryGene");
    Option queryGeneOption = OptionBuilder.create();
    addOption(queryGeneOption);

    addOption(OptionBuilder.hasArg().withArgName("outfile").withDescription("Output filename prefix")
            .withLongOpt("outfile").isRequired().create('o'));

}

From source file:com.boundary.sdk.event.EventCLI.java

@SuppressWarnings("static-access")
private void addFingerprintFieldsOption() {
    optionFingerprintFields = OptionBuilder.withArgName("field-name").hasArg().hasArgs(16)
            .withValueSeparator(':').isRequired()
            .withDescription("The fields of the event used to calculate the event fingerprint.")
            .withLongOpt("fingerprint-fields").create(OPTION_FINGERPRINT_FIELDS);
    options.addOption(optionFingerprintFields);
}

From source file:BigramRelativeFrequency.java

/**
 * Runs this tool./*from  w w w . j av  a2 s .  c om*/
 */
@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));
    options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("output path").create(OUTPUT));
    options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("number of reducers")
            .create(NUM_REDUCERS));

    CommandLine cmdline;
    CommandLineParser parser = new GnuParser();

    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Error parsing command line: " + exp.getMessage());
        return -1;
    }

    if (!cmdline.hasOption(INPUT) || !cmdline.hasOption(OUTPUT)) {
        System.out.println("args: " + Arrays.toString(args));
        HelpFormatter formatter = new HelpFormatter();
        formatter.setWidth(120);
        formatter.printHelp(this.getClass().getName(), options);
        ToolRunner.printGenericCommandUsage(System.out);
        return -1;
    }

    String inputPath = cmdline.getOptionValue(INPUT);
    String outputPath = cmdline.getOptionValue(OUTPUT);
    int reduceTasks = cmdline.hasOption(NUM_REDUCERS) ? Integer.parseInt(cmdline.getOptionValue(NUM_REDUCERS))
            : 1;

    LOG.info("Tool name: " + BigramRelativeFrequency.class.getSimpleName());
    LOG.info(" - input path: " + inputPath);
    LOG.info(" - output path: " + outputPath);
    LOG.info(" - num reducers: " + reduceTasks);

    Job job = Job.getInstance(getConf());
    job.setJobName(BigramRelativeFrequency.class.getSimpleName());
    job.setJarByClass(BigramRelativeFrequency.class);

    job.setNumReduceTasks(reduceTasks);

    FileInputFormat.setInputPaths(job, new Path(inputPath));
    FileOutputFormat.setOutputPath(job, new Path(outputPath));

    job.setMapOutputKeyClass(PairOfStrings.class);
    job.setMapOutputValueClass(FloatWritable.class);
    job.setOutputKeyClass(PairOfStrings.class);
    job.setOutputValueClass(FloatWritable.class);
    //job.setOutputFormatClass(SequenceFileOutputFormat.class);

    job.setMapperClass(MyMapper.class);
    job.setCombinerClass(MyCombiner.class);
    job.setReducerClass(MyReducer.class);
    job.setPartitionerClass(MyPartitioner.class);

    // Delete the output directory if it exists already.
    Path outputDir = new Path(outputPath);
    FileSystem.get(getConf()).delete(outputDir, true);

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

    return 0;
}

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

/**
  * Build command line options object./*from   w ww .j  a v  a2s .  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 idMsg = "ID of the user whose connections are to be fetched.";
    OptionBuilder.withArgName("id");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(idMsg);
    Option id = OptionBuilder.create(ID_OPTION);
    opts.addOption(id);

    String emailMsg = "Email of the user whose connections are to be fetched.";
    OptionBuilder.withArgName("email");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(emailMsg);
    Option email = OptionBuilder.create(EMAIL_OPTION);
    opts.addOption(email);

    String urlMsg = "Profile URL of the user whose connections are to be fetched.";
    OptionBuilder.withArgName("url");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(urlMsg);
    Option url = OptionBuilder.create(URL_OPTION);
    opts.addOption(url);

    return opts;
}

From source file:edu.umd.gorden2.BooleanRetrievalHBase.java

/**
 * Runs this tool.//  w ww . j av  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(INDEX));
    options.addOption(
            OptionBuilder.withArgName("path").hasArg().withDescription("output path").create(COLLECTION));

    CommandLine cmdline = null;
    CommandLineParser parser = new GnuParser();

    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Error parsing command line: " + exp.getMessage());
        System.exit(-1);
    }

    if (!cmdline.hasOption(INDEX) || !cmdline.hasOption(COLLECTION)) {
        System.out.println("args: " + Arrays.toString(args));
        HelpFormatter formatter = new HelpFormatter();
        formatter.setWidth(120);
        //formatter.printHelp(LookupPostings.class.getName(), options);
        ToolRunner.printGenericCommandUsage(System.out);
        System.exit(-1);
    }

    String indexPath = cmdline.getOptionValue(INDEX);
    String collectionPath = cmdline.getOptionValue(COLLECTION);

    if (collectionPath.endsWith(".gz")) {
        System.out.println("gzipped collection is not seekable: use compressed version!");
        System.exit(-1);
    }

    Configuration conf = getConf();
    conf.addResource(new Path("/etc/hbase/conf/hbase-site.xml"));

    Configuration hbaseConfig = HBaseConfiguration.create(conf);
    HConnection hbaseConnection = HConnectionManager.createConnection(hbaseConfig);
    table = hbaseConnection.getTable(indexPath);

    FileSystem fs = FileSystem.get(conf);
    collection = fs.open(new Path(collectionPath));
    stack = new Stack<Set<Integer>>();

    //initialize(indexPath, collectionPath, fs);

    String[] queries = { "outrageous fortune AND", "white rose AND", "means deceit AND",
            "white red OR rose AND pluck AND", "unhappy outrageous OR good your AND OR fortune AND" };

    for (String q : queries) {
        System.out.println("Query: " + q);

        runQuery(q);
        System.out.println("");
    }

    return 1;
}

From source file:edu.umd.JBizz.BuildPersonalizedPageRankRecords.java

/**
 * Runs this tool./*from  w w w  . ja  v  a  2 s . c  o  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));
    options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("output path").create(OUTPUT));
    options.addOption(
            OptionBuilder.withArgName("num").hasArg().withDescription("number of nodes").create(NUM_NODES));
    options.addOption(OptionBuilder.withArgName("sources").hasArg().withDescription("Personalization Nodes")
            .create(SOURCES));

    CommandLine cmdline;
    CommandLineParser parser = new GnuParser();

    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Error parsing command line: " + exp.getMessage());
        return -1;
    }

    if (!cmdline.hasOption(INPUT) || !cmdline.hasOption(OUTPUT) || !cmdline.hasOption(NUM_NODES)
            || !cmdline.hasOption(SOURCES)) {
        System.out.println("args: " + Arrays.toString(args));
        HelpFormatter formatter = new HelpFormatter();
        formatter.setWidth(120);
        formatter.printHelp(this.getClass().getName(), options);
        ToolRunner.printGenericCommandUsage(System.out);
        return -1;
    }

    String inputPath = cmdline.getOptionValue(INPUT);
    String outputPath = cmdline.getOptionValue(OUTPUT);
    int n = Integer.parseInt(cmdline.getOptionValue(NUM_NODES));
    String sources = cmdline.getOptionValue(SOURCES);

    String[] sourceList = sources.trim().split(",");
    int numSources = sourceList.length;

    int source = Integer.parseInt(sourceList[0]);

    int[] sourceNodes = new int[numSources];
    for (int i = 0; i < numSources; i++) {
        sourceNodes[i] = Integer.parseInt(sourceList[i]);
    }

    LOG.info("Tool name: " + BuildPersonalizedPageRankRecords.class.getSimpleName());
    LOG.info(" - inputDir: " + inputPath);
    LOG.info(" - outputDir: " + outputPath);
    LOG.info(" - numNodes: " + n);
    LOG.info("source list: " + sourceList);
    LOG.info("first source: " + source);

    Configuration conf = getConf();
    conf.setInt(NODE_CNT_FIELD, n);
    conf.setInt("mapred.min.split.size", 1024 * 1024 * 1024);
    conf.setInt(SOURCE, source);
    conf.setInt(NUM_SOURCES, numSources);
    conf.set(SOURCE_NODES, sources);

    Job job = Job.getInstance(conf);
    job.setJobName(BuildPersonalizedPageRankRecords.class.getSimpleName() + ":" + inputPath);
    job.setJarByClass(BuildPersonalizedPageRankRecords.class);

    job.setNumReduceTasks(0);

    FileInputFormat.addInputPath(job, new Path(inputPath));
    FileOutputFormat.setOutputPath(job, new Path(outputPath));

    job.setInputFormatClass(TextInputFormat.class);
    job.setOutputFormatClass(SequenceFileOutputFormat.class);

    job.setMapOutputKeyClass(IntWritable.class);
    job.setMapOutputValueClass(PageRankNode.class);

    job.setOutputKeyClass(IntWritable.class);
    job.setOutputValueClass(PageRankNode.class);

    job.setMapperClass(MyMapper.class);

    // Delete the output directory if it exists already.
    FileSystem.get(conf).delete(new Path(outputPath), true);

    job.waitForCompletion(true);

    return 0;
}

From source file:com.googleapis.ajax.services.example.ResourceBundleGenerator.java

/**
 * Builds the options.//from w  w  w  .jav a2s. 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 resourceMsg = "Path to the default resource bundle (without .properties).";
    OptionBuilder.withArgName("resource");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(resourceMsg);
    Option resource = OptionBuilder.create(RESOURCE_OPTION);
    opts.addOption(resource);

    String languagesMsg = "Comma separated list of languages. e.g. de,fr,es";
    OptionBuilder.withArgName("languages");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(languagesMsg);
    Option languages = OptionBuilder.create(LANGUAGES_OPTION);
    opts.addOption(languages);

    return opts;
}