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:geomesa.tutorial.QueryTutorial.java

/**
 * Main entry point. Executes queries against an existing GDELT dataset.
 *
 * @param args//from  w w w . j ava  2  s.c om
 *
 * @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 = (AccumuloFeatureStore) 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'
}

From source file:edu.umd.cloud9.collection.wikipedia.CountWikipediaPages.java

@SuppressWarnings("static-access")
@Override//from   w  w  w.  j  ava 2 s  .  c o  m
public int run(String[] args) throws Exception {
    Options options = new Options();
    options.addOption(
            OptionBuilder.withArgName("path").hasArg().withDescription("XML dump file").create(INPUT_OPTION));
    options.addOption(OptionBuilder.withArgName("en|sv|de|cs|es|zh|ar|tr").hasArg()
            .withDescription("two-letter language code").create(LANGUAGE_OPTION));

    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_OPTION)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(this.getClass().getName(), options);
        ToolRunner.printGenericCommandUsage(System.out);
        return -1;
    }

    String language = "en"; // Assume 'en' by default.
    if (cmdline.hasOption(LANGUAGE_OPTION)) {
        language = cmdline.getOptionValue(LANGUAGE_OPTION);
        if (language.length() != 2) {
            System.err.println("Error: \"" + language + "\" unknown language!");
            return -1;
        }
    }

    String inputPath = cmdline.getOptionValue(INPUT_OPTION);

    LOG.info("Tool name: " + this.getClass().getName());
    LOG.info(" - XML dump file: " + inputPath);
    LOG.info(" - language: " + language);

    Job job = Job.getInstance(getConf());
    job.setJarByClass(CountWikipediaPages.class);
    job.setJobName(String.format("CountWikipediaPages[%s: %s, %s: %s]", INPUT_OPTION, inputPath,
            LANGUAGE_OPTION, language));

    job.setNumReduceTasks(0);

    FileInputFormat.setInputPaths(job, new Path(inputPath));

    if (language != null) {
        job.getConfiguration().set("wiki.language", language);
    }

    job.setInputFormatClass(WikipediaPageInputFormat.class);
    job.setOutputFormatClass(NullOutputFormat.class);

    job.setMapperClass(MyMapper.class);

    job.waitForCompletion(true);

    return 0;
}

From source file:com.github.errantlinguist.latticevisualiser.ArgParser.java

/**
 * Creates and adds a lattice infile option to a given {@link Options}
 * object.//from ww w.ja v  a2  s .co m
 * 
 * @param options
 *            The <code>Options</code> object to add to.
 */
private static void addLatticeInfileOption(final Options options) {
    OptionBuilder.isRequired(true);
    OptionBuilder.withLongOpt(LATTICE_INFILE_KEY_LONG);
    OptionBuilder.withDescription(LATTICE_INFILE_DESCR);
    OptionBuilder.hasArg();
    OptionBuilder.withArgName(INFILE_ARG_NAME);
    OptionBuilder.withType(File.class);
    final Option latticeInfile = OptionBuilder.create(LATTICE_INFILE_KEY);
    options.addOption(latticeInfile);
}

From source file:edu.umd.cloud9.collection.wikipedia.DemoCountWikipediaPages.java

@SuppressWarnings("static-access")
@Override//from w  ww  .java2  s.  co  m
public int run(String[] args) throws Exception {
    Options options = new Options();
    options.addOption(
            OptionBuilder.withArgName("path").hasArg().withDescription("XML dump file").create(INPUT_OPTION));

    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_OPTION)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(this.getClass().getName(), options);
        ToolRunner.printGenericCommandUsage(System.out);
        return -1;
    }

    String inputPath = cmdline.getOptionValue(INPUT_OPTION);

    LOG.info("Tool name: " + this.getClass().getName());
    LOG.info(" - XML dump file: " + inputPath);

    JobConf conf = new JobConf(getConf(), DemoCountWikipediaPages.class);
    conf.setJobName(String.format("DemoCountWikipediaPages[%s: %s]", INPUT_OPTION, inputPath));

    conf.setNumMapTasks(10);
    conf.setNumReduceTasks(0);

    FileInputFormat.setInputPaths(conf, new Path(inputPath));

    conf.setInputFormat(WikipediaPageInputFormat.class);
    conf.setOutputFormat(NullOutputFormat.class);

    conf.setMapperClass(MyMapper.class);

    JobClient.runJob(conf);

    return 0;
}

From source file:com.etsy.arbiter.Arbiter.java

/**
 * Construct the CLI Options/*from  www. j  a v  a  2s. c  om*/
 *
 * @return The Options object representing the supported CLI options
 */
@SuppressWarnings("static-access")
private static Options getOptions() {
    Option config = OptionBuilder.withArgName("config").withLongOpt("config").hasArgs()
            .withDescription("Configuration file").create("c");

    Option lowPrecedenceConfig = OptionBuilder.withArgName("lowPrecedenceConfig")
            .withLongOpt("low-priority-config").hasArgs().withDescription("Low-priority configuration file")
            .create("l");

    Option inputFile = OptionBuilder.withArgName("input").withLongOpt("input").hasArgs()
            .withDescription("Input Arbiter workflow file").create("i");

    Option outputDir = OptionBuilder.withArgName("output").withLongOpt("output").hasArg()
            .withDescription("Output directory").create("o");

    Option help = OptionBuilder.withArgName("help").withLongOpt("help").withDescription("Print usage")
            .create("h");

    Option graphviz = OptionBuilder.withArgName("graphviz").withLongOpt("graphviz").hasOptionalArg()
            .withDescription("Generate the Graphviz DOT file and PNG").create("g");

    Options options = new Options();
    options.addOption(config).addOption(lowPrecedenceConfig).addOption(inputFile).addOption(outputDir)
            .addOption(help).addOption(graphviz);

    return options;
}

From source file:fr.ens.biologie.genomique.eoulsan.actions.EMRExecAction.java

/**
 * Create options for command line// w w w  .ja  v a 2s. co  m
 * @return an Options object
 */
@SuppressWarnings("static-access")
private static Options makeOptions() {

    // create Options object
    final Options options = new Options();

    // Help option
    options.addOption("h", "help", false, "display this help");

    // Description option
    options.addOption(OptionBuilder.withArgName("description").hasArg().withDescription("job description")
            .withLongOpt("desc").create('d'));

    return options;
}

From source file:edu.umd.cloud9.example.bigram.BigramCount.java

/**
 * Runs this tool./*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 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: " + BigramCount.class.getSimpleName());
    LOG.info(" - input path: " + inputPath);
    LOG.info(" - output path: " + outputPath);
    LOG.info(" - num reducers: " + reduceTasks);

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

    job.setNumReduceTasks(reduceTasks);

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

    job.setMapOutputKeyClass(Text.class);
    job.setMapOutputValueClass(IntWritable.class);
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(IntWritable.class);
    job.setOutputFormatClass(SequenceFileOutputFormat.class);

    job.setMapperClass(MyMapper.class);
    job.setCombinerClass(MyReducer.class);
    job.setReducerClass(MyReducer.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:edu.umd.cloud9.collection.wikipedia.DumpWikipediaToPlainText.java

@SuppressWarnings("static-access")
@Override/*  w  w  w.ja  v  a  2 s. c  o  m*/
public int run(String[] args) throws Exception {
    Options options = new Options();
    options.addOption(
            OptionBuilder.withArgName("path").hasArg().withDescription("XML dump file").create(INPUT_OPTION));
    options.addOption(
            OptionBuilder.withArgName("path").hasArg().withDescription("output path").create(OUTPUT_OPTION));

    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_OPTION) || !cmdline.hasOption(OUTPUT_OPTION)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(this.getClass().getName(), options);
        ToolRunner.printGenericCommandUsage(System.out);
        return -1;
    }

    String inputPath = cmdline.getOptionValue(INPUT_OPTION);
    String outputPath = cmdline.getOptionValue(OUTPUT_OPTION);

    LOG.info("Tool name: " + this.getClass().getName());
    LOG.info(" - XML dump file: " + inputPath);
    LOG.info(" - output path: " + outputPath);

    JobConf conf = new JobConf(getConf(), DemoCountWikipediaPages.class);
    conf.setJobName(String.format("DumpWikipediaToPlainText[%s: %s, %s: %s]", INPUT_OPTION, inputPath,
            OUTPUT_OPTION, outputPath));

    conf.setNumMapTasks(10);
    conf.setNumReduceTasks(0);

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

    conf.setInputFormat(WikipediaPageInputFormat.class);
    conf.setOutputFormat(TextOutputFormat.class);

    conf.setMapperClass(MyMapper.class);
    conf.setOutputKeyClass(Text.class);
    conf.setOutputValueClass(Text.class);

    JobClient.runJob(conf);

    return 0;
}

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

@SuppressWarnings("static-access")
private void addApiHostOption() {
    optionApiHost = OptionBuilder.withArgName("api_host)").hasArg()
            .withDescription("Boundary API Host. defaults to api.boundary.com").create(OPTION_API_HOST);
    options.addOption(optionApiHost);//from w  ww .  j  a  v a2 s .c o m
}

From source file:ch.qos.logback.decoder.cli.MainArgs.java

/**
 * Creates the options for the command-line arguments
 *
 * @return the newly created options//from  www.  j a va2s . c o m
 */
@SuppressWarnings("static-access")
private final Options createOptions() {
    Options opts = new Options();

    Option help = OptionBuilder.withDescription("Print this help message and exit").withLongOpt("help")
            .create("h");
    opts.addOption(help);

    Option version = OptionBuilder.withDescription("Print version information and exit").withLongOpt("version")
            .create("v");
    opts.addOption(version);

    Option layoutPattern = OptionBuilder.withArgName("pattern").hasArg()
            .withDescription("Layout pattern to use (overrides file's pattern)").withLongOpt("layout")
            .create("p");
    opts.addOption(layoutPattern);

    Option infile = OptionBuilder.withArgName("path").hasArg()
            .withDescription("Log file to parse (default: stdin)").withLongOpt("input-file").create("f");
    opts.addOption(infile);

    Option debug = OptionBuilder.withDescription("Enable debug mode").withLongOpt("debug").create("d");
    opts.addOption(debug);

    Option verbose = OptionBuilder.withDescription("Be verbose when printing information")
            .withLongOpt("verbose").create();
    opts.addOption(verbose);

    Option property = OptionBuilder.withArgName("property=value").hasArgs(2).withValueSeparator()
            .withDescription("use value for given property").create("D");
    opts.addOption(property);

    return opts;
}