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:ivory.app.PreprocessClueWebEnglish.java

/**
 * Runs this tool.//from   w w w.  j  a v a2s .  c  om
 */
@SuppressWarnings({ "static-access" })
@Override
public int run(String[] args) throws Exception {
    Options options = new Options();
    ;

    options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("(required) collection path")
            .create(PreprocessCollection.COLLECTION_PATH));
    options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("(required) index path")
            .create(PreprocessCollection.INDEX_PATH));
    options.addOption(
            OptionBuilder.withArgName("num").hasArg().withDescription("(required) segment").create(SEGMENT));

    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(PreprocessCollection.COLLECTION_PATH)
            || !cmdline.hasOption(PreprocessCollection.INDEX_PATH) || !cmdline.hasOption(SEGMENT)) {
        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 collection = cmdline.getOptionValue(PreprocessCollection.COLLECTION_PATH);
    String indexPath = cmdline.getOptionValue(PreprocessCollection.INDEX_PATH);
    int segment = Integer.parseInt(cmdline.getOptionValue(SEGMENT));

    LOG.info("Tool name: " + PreprocessClueWebEnglish.class.getSimpleName());
    LOG.info(" - collection path: " + collection);
    LOG.info(" - index path: " + indexPath);
    LOG.info(" - segement: " + segment);

    Configuration conf = getConf();
    FileSystem fs = FileSystem.get(conf);

    // Create the index directory if it doesn't already exist.
    Path p = new Path(indexPath);
    if (!fs.exists(p)) {
        LOG.info("index path doesn't exist, creating...");
        fs.mkdirs(p);
    } else {
        LOG.info("Index directory " + p + " already exists!");
        return -1;
    }

    RetrievalEnvironment env = new RetrievalEnvironment(indexPath, fs);
    Path mappingFile = env.getDocnoMappingData();
    new ClueWarcDocnoMappingBuilder().build(new Path(collection), mappingFile, conf);

    conf.set(Constants.CollectionName, "ClueWeb:English:Segment" + segment);
    conf.set(Constants.CollectionPath, collection);
    conf.set(Constants.IndexPath, indexPath);
    conf.set(Constants.InputFormat, SequenceFileInputFormat.class.getCanonicalName());
    conf.set(Constants.Tokenizer, GalagoTokenizer.class.getCanonicalName());
    conf.set(Constants.DocnoMappingClass, ClueWarcDocnoMapping.class.getCanonicalName());
    conf.set(Constants.DocnoMappingFile, env.getDocnoMappingData().toString());

    conf.setInt(Constants.DocnoOffset, DOCNO_OFFSETS[segment]);
    conf.setInt(Constants.MinDf, 10);
    conf.setInt(Constants.MaxDf, Integer.MAX_VALUE);

    new BuildTermDocVectors(conf).run();
    new ComputeGlobalTermStatistics(conf).run();
    new BuildDictionary(conf).run();
    new BuildIntDocVectors(conf).run();

    new BuildIntDocVectorsForwardIndex(conf).run();
    new BuildTermDocVectorsForwardIndex(conf).run();

    return 0;
}

From source file:edu.vt.cs.irwin.etdscraper.Configuration.java

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

    options.addOption(new Option("help", "prints this message"));
    options.addOption(OptionBuilder.withArgName("jdbcUrl").hasArg()
            .withDescription("URL for JDBC connection. Examples include:\n" + "- jdbc:sqlite:etd.db\n"
                    + "- jdbc:mysql://localhost/dbName?username=root&password=Passw0rd\n"
                    + "- jdbc:postgresql://localhost/test?user=fred&password=secret&ssl=true")
            .create("jdbcUrl"));
    options.addOption(OptionBuilder.withArgName("nameFixFile").hasArg()
            .withDescription("File path to definitions for name fixing rules").create("nameFixFile"));
    options.addOption(OptionBuilder.withArgName("excelFile").hasArg()
            .withDescription("Path to file that contains additional ETD data").create("excelFile"));

    return options;
}

From source file:com.google.code.stackexchange.client.examples.BadgesApiExample.java

/**
 * Builds the options.//  w ww  . jav  a2  s .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 consumerKeyMsg = "You API Key.";
    OptionBuilder.withArgName("key");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(consumerKeyMsg);
    Option consumerKey = OptionBuilder.create(APPLICATION_KEY_OPTION);
    opts.addOption(consumerKey);

    String siteNameMsg = "Your site name.";
    OptionBuilder.withArgName("site");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(siteNameMsg);
    Option siteName = OptionBuilder.create(STACK_EXCHANGE_SITE);
    opts.addOption(siteName);

    return opts;
}

From source file:edu.umd.cloud9.example.bfs.FindNodeAtDistance.java

@SuppressWarnings("static-access")
@Override/*from w ww  .  j  a va2s .  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));
    options.addOption(
            OptionBuilder.withArgName("num").hasArg().withDescription("distance").create(DISTANCE_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)
            || !cmdline.hasOption(DISTANCE_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);
    int distance = Integer.parseInt(cmdline.getOptionValue(DISTANCE_OPTION));

    LOG.info("Tool name: " + this.getClass().getName());
    LOG.info(" - inputDir: " + inputPath);
    LOG.info(" - outputDir: " + outputPath);
    LOG.info(" - distance: " + distance);

    Job job = new Job(getConf(), String.format("FindNodeAtDistance[%s: %s, %s: %s, %s: %d]", INPUT_OPTION,
            inputPath, OUTPUT_OPTION, outputPath, DISTANCE_OPTION, distance));
    job.setJarByClass(FindNodeAtDistance.class);

    job.setNumReduceTasks(0);

    job.getConfiguration().setInt(DISTANCE_OPTION, distance);
    job.getConfiguration().setInt("mapred.min.split.size", 1024 * 1024 * 1024);

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

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

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

    job.setMapperClass(MyMapper.class);

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

    job.waitForCompletion(true);

    return 0;
}

From source file:jlite.cli.JobSubmit.java

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

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

    options.addOption(OptionBuilder.withDescription("enables extra debug output").create("debug"));

    options.addOption(OptionBuilder.withArgName("dir_path")
            .withDescription("search input files in the specified directory (default is current directory)")
            .hasArg().create("in"));

    options.addOption(OptionBuilder.withArgName("ce_id")
            .withDescription("send job to specified computing element").hasArg().create("r"));

    options.addOption(OptionBuilder.withArgName("file_path").withDescription("write job id to specified file")
            .hasArg().create("o"));

    options.addOption(OptionBuilder.withArgName("id_string")
            .withDescription("delegation id (default is user name)").hasArg().create("d"));

    options.addOption(OptionBuilder.withDescription("automatic proxy delegation").create("a"));

    options.addOption(OptionBuilder.withArgName("service_URL").withDescription("WMProxy service endpoint")
            .hasArg().create("e"));

    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("protocol")
    //                .withDescription("protocol to be used for file tranfer {gsiftp,https} (default is gsiftp)")
    //                .hasArg()
    //                .create("proto"));

    return options;
}

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

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

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

    OptionBuilder.withDescription("Make the cluster sizes different.");
    option = OptionBuilder.create("sizes");
    options.addOption(option);

    OptionBuilder.withArgName("k");
    OptionBuilder.isRequired();
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("The number of clusters.");
    option = OptionBuilder.create("k");
    options.addOption(option);

    OptionBuilder.withArgName("noisyfeatures");
    OptionBuilder.isRequired();
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("The number of noisy features.");
    option = OptionBuilder.create("dn");
    options.addOption(option);

    OptionBuilder.withArgName("features");
    OptionBuilder.isRequired();
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("The number of non-noisy (clustered/separated) features.");
    option = OptionBuilder.create("d");
    options.addOption(option);

    OptionBuilder.withArgName("clusterSeparation");
    OptionBuilder.isRequired();
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("The cluster separation (between -1.0 and +1.0).");
    option = OptionBuilder.create("s");
    options.addOption(option);

    return options;
}

From source file:com.dumontierlab.pdb2rdf.cluster.ClusterServer.java

@SuppressWarnings("static-access")
private static Options createOptions() {
    Options options = new Options();
    Option dirOption = OptionBuilder.withArgName("path")
            .withDescription("Directory where input files are located").hasArg(true).isRequired(true)
            .create("dir");
    options.addOption(dirOption);/*from   www. ja v  a2s .  c o m*/
    options.addOption("gzip", false, "Input is given as gzip file(s)");

    Option portOption = OptionBuilder.withArgName("number")
            .withDescription("The port number to listen for client connections.").hasArg(true).create("port");
    options.addOption(portOption);
    return options;
}

From source file:crossspectrumapp.CrossSpectrumCommandLine.java

boolean parseCommand(String[] args, String programName, String version) {
    ret = true;//from  w w w .j  a v a  2s. co  m

    Options options = new Options();

    options.addOption(new Option("help", "print this message"));
    options.addOption(new Option("version", "print the version information and exit"));

    options.addOption(new Option("logfreq", "use logarithmic frequncy access"));
    options.addOption(new Option("logpower", "log scale for power or amplitude"));
    options.addOption(
            new Option("nodetrend", "Do not detrend (subtract linear fit) the data before transform."));

    options.addOption(
            OptionBuilder.withArgName("out").hasArg().withDescription("output filename").create("outfile"));
    options.addOption(OptionBuilder.withArgName("geometry").hasArg()
            .withDescription("image size <X>x<Y> [default=640x480]").create("geom"));

    options.addOption(OptionBuilder.withArgName("channel").hasArgs()
            .withDescription("channel <name,type> multiples accepted").create("chan"));
    options.addOption(OptionBuilder.withArgName("server").hasArg()
            .withDescription("server <URL> [default=best match]").create("server"));
    options.addOption(OptionBuilder.withArgName("ctype").hasArg()
            .withDescription("channel type eg (raw, rds, minute-trend [default=best match]").create("ctype"));

    options.addOption(
            OptionBuilder.withArgName("start").hasArg().withDescription("GPS start time").create("start"));
    options.addOption(
            OptionBuilder.withArgName("duration").hasArg().withDescription("duration (seconds)").create("dur"));
    options.addOption(OptionBuilder.withArgName("xticks").hasArg()
            .withDescription("tick marks/grid lines on time axis").create("xticks"));
    options.addOption(OptionBuilder.withArgName("yticks").hasArg()
            .withDescription("tick marks/grid lines on freq axis").create("yticks"));
    options.addOption(OptionBuilder.withArgName("secpfft").hasArg()
            .withDescription("seconds per fft [default=1]").create("secpfft"));
    options.addOption(OptionBuilder.withArgName("fmin").hasArg()
            .withDescription("min frequency to plot [default=1/secpfft]").create("fmin"));
    options.addOption(OptionBuilder.withArgName("fmax").hasArg()
            .withDescription("max frequency to plot [default=<sample rate>/2]").create("fmax"));
    options.addOption(OptionBuilder.withArgName("overlap").hasArg()
            .withDescription("fft overlap (0-.9) [default=0.5]").create("overlap"));

    CommandLineParser parser = new GnuParser();

    wantHelp = false;
    ermsg = new StringBuilder();

    try {
        // parse the command line arguments
        line = parser.parse(options, args);
    } catch (ParseException exp) {
        // oops, something went wrong
        System.err.println("Command parsing failed.  Reason: " + exp.getMessage());
        wantHelp = true;
        line = null;
    }
    if (line != null) {
        if (line.hasOption("version")) {
            System.out.println(programName + " - version " + version);
            ret = false;
        }

        wantHelp = line.hasOption("help");
        logFreq = line.hasOption("logfreq");
        logPower = line.hasOption("logpower");
        detrend = !line.hasOption("nodetrend");

        startGPS = getIntegerOpt("start");
        duration = getIntegerOpt("dur");
        xTicks = getIntegerOpt("xticks");
        yTicks = getIntegerOpt("yticks");

        secPerFFT = getFloatOpt("secpfft");
        overlap = getFloatOpt("overlap");
        fmin = getFloatOpt("fmin");
        fmax = getFloatOpt("fmax");

        if (line.hasOption("outfile")) {
            ofileName = line.getOptionValue("outfile");
        }
        String val;

        Matcher m;

        if (line.hasOption("geom")) {
            val = line.getOptionValue("geom");
            Pattern gp = Pattern.compile("(\\d+)x(\\d+)");
            m = gp.matcher(val);
            if (m.find()) {
                String sx = m.group(1);
                String sy = m.group(2);
                if (sx.matches(intpat) && sy.matches(intpat)) {
                    outX = Integer.parseInt(sx);
                    outY = Integer.parseInt(sy);
                } else {
                    ermsg.append("can't parse geometry value (").append(val).append(")");
                    wantHelp = true;
                    ret = false;
                }
            } else {
                ermsg.append("can't parse geometry value (").append(val).append(")");
                wantHelp = true;
                ret = false;
            }
        }

        if (line.hasOption("chan")) {
            channelNames = line.getOptionValues("chan");
        }
        if (line.hasOption("server")) {
            server = line.getOptionValue("server");
        }

        if (line.hasOption("ctype")) {
            cType = line.getOptionValue("ctype");
        }

    }
    if (ermsg.length() > 0) {
        System.out.println("Command error:\n" + ermsg);
        wantHelp = true;
        ret = false;
    }
    if (wantHelp) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(programName, options);
        ret = false;
    }
    return ret;

}

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

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

    // init valid command line options
    OptionBuilder.withArgName("radius");
    OptionBuilder.hasArg();//from   w  w w. j  av a  2 s  . c o m
    OptionBuilder.withDescription("The radius of the circle on which the gaussians are located.");
    Option option = OptionBuilder.create("r");
    options.addOption(option);

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

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

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

    return options;
}

From source file:edu.fullerton.timeseriesapp.TimeSeriesCommandLine.java

boolean parseCommand(String[] args, String programName, String version) {
    ret = true;/*from   w  w  w  . j  av  a  2s  .co m*/

    Options options = new Options();

    options.addOption(new Option("help", "print this message"));
    options.addOption(new Option("version", "print the version information and exit"));

    options.addOption(new Option("semilog", "log scale Y-axis"));
    options.addOption(
            new Option("nodetrend", "Do not detrend (subtract linear fit) the data before transform."));

    options.addOption(
            OptionBuilder.withArgName("out").hasArg().withDescription("output filename").create("outfile"));
    options.addOption(OptionBuilder.withArgName("geometry").hasArg()
            .withDescription("image size <X>x<Y> [default=640x480]").create("geom"));

    options.addOption(OptionBuilder.withArgName("channel").hasArgs()
            .withDescription("channel <name,type> multiples accepted").create("chan"));
    options.addOption(OptionBuilder.withArgName("server").hasArg()
            .withDescription("server <URL> [default=best match]").create("server"));
    options.addOption(OptionBuilder.withArgName("ctype").hasArg()
            .withDescription("channel type eg (raw, rds, minute-trend [default=best match]").create("ctype"));

    options.addOption(
            OptionBuilder.withArgName("start").hasArg().withDescription("GPS start time").create("start"));
    options.addOption(
            OptionBuilder.withArgName("duration").hasArg().withDescription("duration (seconds)").create("dur"));
    options.addOption(OptionBuilder.withArgName("xticks").hasArg()
            .withDescription("tick marks/grid lines on time axis").create("xticks"));
    options.addOption(OptionBuilder.withArgName("yticks").hasArg()
            .withDescription("tick marks/grid lines on freq axis").create("yticks"));
    options.addOption(OptionBuilder.withArgName("timeaxis").hasArg()
            .withDescription("time axis label (utc, gps, dt [default=dt]").create("timeaxis"));

    CommandLineParser parser = new GnuParser();

    wantHelp = false;
    try {
        // parse the command line arguments
        line = parser.parse(options, args);
    } catch (ParseException exp) {
        // oops, something went wrong
        System.err.println("Command parsing failed.  Reason: " + exp.getMessage());
        wantHelp = true;
        line = null;
    }
    if (line != null) {
        if (line.hasOption("version")) {
            System.out.println(programName + " - version " + version);
            ret = false;
        }

        wantHelp = line.hasOption("help");
        logX = line.hasOption("logfreq");
        logY = line.hasOption("logpower");
        detrend = !line.hasOption("nodetrend");

        startGPS = getIntegerOpt("start");
        duration = getIntegerOpt("dur");
        xTicks = getIntegerOpt("xticks");
        yTicks = getIntegerOpt("yticks");

        secPerFFT = getFloatOpt("secpfft");
        overlap = getFloatOpt("overlap");
        fmin = getFloatOpt("fmin");
        fmax = getFloatOpt("fmax");

        if (line.hasOption("outfile")) {
            ofileName = line.getOptionValue("outfile");
        }
        String val;

        Matcher m;

        if (line.hasOption("geom")) {
            val = line.getOptionValue("geom");
            Pattern gp = Pattern.compile("(\\d+)x(\\d+)");
            m = gp.matcher(val);
            if (m.find()) {
                String sx = m.group(1);
                String sy = m.group(2);
                if (sx.matches(intpat) && sy.matches(intpat)) {
                    outX = Integer.parseInt(sx);
                    outY = Integer.parseInt(sy);
                } else {
                    ermsg += "can't parse geometry value (" + val + ")";
                    wantHelp = true;
                    ret = false;
                }
            } else {
                ermsg += "can't parse geometry value (" + val + ")";
                wantHelp = true;
                ret = false;
            }
        }

        if (line.hasOption("chan")) {
            channelNames = line.getOptionValues("chan");
        }
        if (line.hasOption("server")) {
            server = line.getOptionValue("server");
        }

        if (line.hasOption("ctype")) {
            cType = line.getOptionValue("ctype");
        }
        if (line.hasOption("timeaxis")) {
            timeAxis = line.getOptionValue("timeaxis");
        } else {
            timeAxis = "dt";
        }

    }
    if (!ermsg.isEmpty()) {
        System.out.println("Command error:\n" + ermsg);
        wantHelp = true;
        ret = false;
    }
    if (wantHelp) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(programName, options);
        ret = false;
    }
    return ret;

}