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:edu.umd.cloud9.example.hbase.HBaseWordCountFetch.java

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

    options.addOption(
            OptionBuilder.withArgName("table").hasArg().withDescription("HBase table name").create(TABLE));
    options.addOption(
            OptionBuilder.withArgName("word").hasArg().withDescription("word to look up").create(WORD));

    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(TABLE) || !cmdline.hasOption(WORD)) {
        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 tableName = cmdline.getOptionValue(TABLE);
    String word = cmdline.getOptionValue(WORD);

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

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

    Get get = new Get(Bytes.toBytes(word));
    Result result = table.get(get);

    int count = Bytes.toInt(result.getValue(HBaseWordCount.CF, HBaseWordCount.COUNT));

    LOG.info("word: " + word + ", count: " + count);

    return 0;
}

From source file:carmen.utils.Utils.java

public static void registerOption(List<Option> options, String option_name, String arg_name, boolean has_arg,
        String description) {/*w  ww.  ja  va2s.c  o m*/
    OptionBuilder.withArgName(arg_name);
    OptionBuilder.hasArg(has_arg);
    OptionBuilder.withDescription(description);
    Option option = OptionBuilder.create(option_name);

    options.add(option);
}

From source file:LookupPostings.java

/**
 * Runs this tool.//from   w ww  .j a  va 2s .  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(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 config = new Configuration();
    FileSystem fs = FileSystem.get(config);
    MapFile.Reader reader = new MapFile.Reader(new Path(indexPath + "/part-r-00000"), config);

    FSDataInputStream collection = fs.open(new Path(collectionPath));
    BufferedReader d = new BufferedReader(new InputStreamReader(collection));

    Text key = new Text();
    PairOfWritables<IntWritable, ArrayListWritable<PairOfInts>> value = new PairOfWritables<IntWritable, ArrayListWritable<PairOfInts>>();

    System.out.println("Looking up postings for the term \"starcross'd\"");
    key.set("starcross'd");

    reader.get(key, value);

    ArrayListWritable<PairOfInts> postings = value.getRightElement();
    for (PairOfInts pair : postings) {
        System.out.println(pair);
        collection.seek(pair.getLeftElement());
        System.out.println(d.readLine());
    }

    key.set("gold");
    reader.get(key, value);
    System.out.println("Complete postings list for 'gold': " + value);

    Int2IntFrequencyDistribution goldHist = new Int2IntFrequencyDistributionEntry();
    postings = value.getRightElement();
    for (PairOfInts pair : postings) {
        goldHist.increment(pair.getRightElement());
    }

    System.out.println("histogram of tf values for gold");
    for (PairOfInts pair : goldHist) {
        System.out.println(pair.getLeftElement() + "\t" + pair.getRightElement());
    }

    key.set("silver");
    reader.get(key, value);
    System.out.println("Complete postings list for 'silver': " + value);

    Int2IntFrequencyDistribution silverHist = new Int2IntFrequencyDistributionEntry();
    postings = value.getRightElement();
    for (PairOfInts pair : postings) {
        silverHist.increment(pair.getRightElement());
    }

    System.out.println("histogram of tf values for silver");
    for (PairOfInts pair : silverHist) {
        System.out.println(pair.getLeftElement() + "\t" + pair.getRightElement());
    }

    key.set("bronze");
    Writable w = reader.get(key, value);

    if (w == null) {
        System.out.println("the term bronze does not appear in the collection");
    }

    collection.close();
    reader.close();

    return 0;
}

From source file:jlite.cli.JobStatus.java

private static Options setupOptions() {
    Options options = new Options();

    options.addOption(OptionBuilder.withDescription("displays usage").create("help"));

    options.addOption(OptionBuilder.withArgName("file_path")
            .withDescription("select JobId(s) from the specified file").hasArg().create("i"));

    options.addOption(OptionBuilder.withArgName("proxyfile")
            .withDescription("non-standard location of proxy cert").hasArg().create("proxypath"));

    options.addOption(OptionBuilder.withArgName("xml").withDescription("output as xml").create("xml"));

    //        options.addOption(OptionBuilder
    //              .withArgName("level")
    //                .withDescription("sets verbosity level of displayed information")
    //                .hasArg()
    //                .create("v"));

    return options;
}

From source file:com.toy.TOYConfig.java

private static final Options get() {
    Option tomcat = OptionBuilder.withArgName("tomcat").isRequired(false).hasArg()
            .withDescription("Tomcat home").create("tomcat");

    Option war = OptionBuilder.withArgName("war").isRequired(false).hasArg().withDescription("WAR file")
            .create("war");

    Option zookeeper = OptionBuilder.withArgName("zookeeper").isRequired().hasArg()
            .withDescription("zookeeper servers list e.g. : node1,node2,node3").create("zookeeper");

    Option queue = OptionBuilder.withArgName("queue").hasArg().withDescription("YARN queue (default : default)")
            .create("queue");

    Option maxmem = OptionBuilder.withArgName("memory").hasArg()
            .withDescription(/*from   w ww  .j  a va 2s.  c  o  m*/
                    "Maximum memory allowed by the YARN container for the Tomcat instance (default : 64M)")
            .create("memory");

    Option ns = OptionBuilder.withArgName("namespace").hasArg()
            .withDescription("Deployment namespace (default : default)").create("namespace");

    Option log4j = OptionBuilder.withArgName("log4j").hasArg()
            .withDescription("Log4j configuration file, will be added to the Tomcat classpath").create("log4j");

    OptionGroup optionGroup = new OptionGroup();
    Option start = OptionBuilder.withArgName("start").hasArg(false)
            .withDescription("Start containers with given WAR").create("start");
    Option stop = OptionBuilder.withArgName("stop").hasArg().hasArg(false)
            .withDescription("Stop containers with given WAR").create("stop");
    Option status = OptionBuilder.withArgName("status").hasArg().hasArg(false)
            .withDescription("Give status about containers").create("status");
    Option add = OptionBuilder.withArgName("add").hasArg().hasArg(false).withDescription("Add new container")
            .create("add");

    optionGroup.addOption(start).addOption(stop).addOption(status).addOption(add).setRequired(true);

    return (new Options()).addOptionGroup(optionGroup).addOption(tomcat).addOption(zookeeper).addOption(war)
            .addOption(queue).addOption(maxmem).addOption(ns);
}

From source file:com.yahoo.yqlplus.engine.tools.YQLPlusRun.java

protected Options createOptions() {
    Options options = new Options();
    options.addOption(new Option("h", "help", false, "Display help"));
    options.addOption(new Option("c", "command", true, "Execute a script from the command line"));
    options.addOption(new Option("s", "source", false, "Dump source of generated script"));
    options.addOption(new Option("v", "verbose", false, "Enable verbose tracing"));
    options.addOption(new Option("p", "path", true, "Add a module directory"));

    // -l <port> (listen on a port? for dev-time running of a web server)
    // a way to import a library?

    // command -h -Dargname=argval -Dargname=argvalue... -c {command} [<file>]

    options.addOption(OptionBuilder.withArgName("argument=value").hasArgs(2).withValueSeparator()
            .withDescription("define named argument").create("D"));
    return options;
}

From source file:com.google.oacurl.options.FetchOptions.java

@SuppressWarnings("static-access")
public FetchOptions() {
    options.addOption("f", "file", true, "File name to POST, rather than stdin");
    options.addOption("X", "request", true, "HTTP method: GET, POST, PUT, or DELETE");
    options.addOption(OptionBuilder.withArgName("method").withLongOpt("header").hasArg()
            .withDescription("Custom header to pass to server").create("H"));
    options.addOption("R", "related", true, "File name (;content/type) for multipart/related");
    options.addOption("t", "content-type", true, "Content-Type header (or ATOM, XML, JSON, CSV, TEXT)");
    options.addOption("i", "include", false, "Include protocol headers in the output");
}

From source file:LookupPostingsCompressed.java

/**
 * Runs this tool./*  www .  j ava  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(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 config = new Configuration();
    FileSystem fs = FileSystem.get(config);
    MapFile.Reader reader = new MapFile.Reader(new Path(indexPath + "/part-r-00000"), config);

    FSDataInputStream collection = fs.open(new Path(collectionPath));
    BufferedReader d = new BufferedReader(new InputStreamReader(collection));

    Text key = new Text();
    BytesWritable value = new BytesWritable();

    System.out.println("Looking up postings for the term \"starcross'd\"");
    key.set("starcross'd");

    reader.get(key, value);

    PairOfWritables<IntWritable, ArrayListWritable<PairOfInts>> postings = PostingReader.readPostings(value);
    for (PairOfInts pair : postings.getRightElement()) {
        System.out.println(pair);
        collection.seek(pair.getLeftElement());
        System.out.println(d.readLine());
    }

    key.set("gold");
    reader.get(key, value);
    postings = PostingReader.readPostings(value);
    System.out.println("Complete postings list for 'gold': " + postings);

    Int2IntFrequencyDistribution goldHist = new Int2IntFrequencyDistributionEntry();
    for (PairOfInts pair : postings.getRightElement()) {
        goldHist.increment(pair.getRightElement());
    }

    System.out.println("histogram of tf values for gold");
    for (PairOfInts pair : goldHist) {
        System.out.println(pair.getLeftElement() + "\t" + pair.getRightElement());
    }

    key.set("silver");
    reader.get(key, value);
    postings = PostingReader.readPostings(value);
    System.out.println("Complete postings list for 'silver': " + postings);

    Int2IntFrequencyDistribution silverHist = new Int2IntFrequencyDistributionEntry();
    for (PairOfInts pair : postings.getRightElement()) {
        silverHist.increment(pair.getRightElement());
    }

    System.out.println("histogram of tf values for silver");
    for (PairOfInts pair : silverHist) {
        System.out.println(pair.getLeftElement() + "\t" + pair.getRightElement());
    }

    key.set("bronze");
    Writable w = reader.get(key, value);

    if (w == null) {
        System.out.println("the term bronze does not appear in the collection");
    }

    collection.close();
    reader.close();

    return 0;
}

From source file:consumer.kafka.client.Consumer.java

private void init(String[] args) throws Exception {

    Options options = new Options();
    this._props = new Properties();

    options.addOption("p", true, "properties filename from the classpath");
    options.addOption("P", true, "external properties filename");

    OptionBuilder.withArgName("property=value");
    OptionBuilder.hasArgs(2);//from www .  j a v  a2 s  .  com
    OptionBuilder.withValueSeparator();
    OptionBuilder.withDescription("use value for given property");
    options.addOption(OptionBuilder.create("D"));

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = parser.parse(options, args);
    if (cmd.hasOption('p')) {
        this._props.load(ClassLoader.getSystemClassLoader().getResourceAsStream(cmd.getOptionValue('p')));
    }
    if (cmd.hasOption('P')) {
        File file = new File(cmd.getOptionValue('P'));
        FileInputStream fStream = new FileInputStream(file);
        this._props.load(fStream);
    }
    this._props.putAll(cmd.getOptionProperties("D"));

}

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

/**
 * Builds the options./*from   www .  ja  v a  2 s  .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 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;
}