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

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

Introduction

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

Prototype

public static OptionBuilder withDescription(String newDescription) 

Source Link

Document

The next Option created will have the specified description

Usage

From source file:org.apache.james.jspf.tester.DNSTestingServerLauncher.java

/**
 * Return the generated Options/* w ww. j a v a 2 s  .  c o m*/
 * 
 * @return options
 */
private static Options generateOptions() {
    Options options = new Options();

    OptionBuilder.withLongOpt(CMD_IP);
    OptionBuilder.withValueSeparator('=');
    OptionBuilder.hasArg();
    OptionBuilder.withArgName("ip");
    OptionBuilder.withDescription("Listening IP (default: 0.0.0.0 for every IP)");
    options.addOption(OptionBuilder.create(CHAR_IP));

    OptionBuilder.withLongOpt(CMD_PORT);
    OptionBuilder.withValueSeparator('=');
    OptionBuilder.hasArg();
    OptionBuilder.withArgName("port");
    OptionBuilder.withDescription("Listening port (default: 53)");
    options.addOption(OptionBuilder.create(CHAR_PORT));

    OptionBuilder.withLongOpt(CMD_FILE);
    OptionBuilder.withValueSeparator('=');
    OptionBuilder.withDescription("YML file name");
    OptionBuilder.withArgName("file");
    OptionBuilder.isRequired();
    OptionBuilder.hasArg();
    options.addOption(OptionBuilder.create(CHAR_FILE));

    OptionBuilder.withLongOpt(CMD_TESTNAME);
    OptionBuilder.withValueSeparator('=');
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("Test name");
    OptionBuilder.withArgName("test");
    OptionBuilder.isRequired();
    options.addOption(OptionBuilder.create(CHAR_TESTNAME));

    return options;
}

From source file:org.apache.james.mpt.app.Main.java

@SuppressWarnings("static-access")
private static void addRunScriptOptions(Options options) {
    // -f <file> runs this script
    options.addOption(OptionBuilder.withArgName("file").hasArg().withDescription("run this script")
            .withLongOpt("file").isRequired().create(FILE_OPTION));

    // -p <port> runs against this port
    options.addOption(OptionBuilder.withArgName("port").hasArg().withDescription("runs against this port")
            .withLongOpt("port").isRequired().create(PORT_OPTION));

    // -h <host> runs against this host
    options.addOption(OptionBuilder.withArgName("host").hasArg()
            .withDescription("runs against this host (defaults to localhost)").withLongOpt("host")
            .isRequired(false).create(HOST_OPTION));
    // -s <shabang> sets shabang
    options.addOption(//from   w w  w .j a  v  a  2 s . c o m
            OptionBuilder.withArgName("shabang").hasArg().withDescription("sets shabang (defaults to empty)")
                    .withLongOpt("shabang").isRequired(false).create(SHABANG_OPTION));
    // -v sets logging to verbose
    options.addOption(OptionBuilder.withDescription("prints lots of logging").withLongOpt("verbose")
            .isRequired(false).create(VERBOSE_OPTION));
}

From source file:org.apache.nutch.api.NutchServer.java

private static Options createOptions() {
    Options options = new Options();
    OptionBuilder.hasArg();/*w w w .ja  v  a  2 s  .c om*/
    OptionBuilder.withArgName("logging level");
    OptionBuilder.withDescription("Select a logging level for the NutchServer: \n"
            + "ALL|CONFIG|FINER|FINEST|INFO|OFF|SEVERE|WARNING");
    options.addOption(OptionBuilder.create(CMD_LOG_LEVEL));

    OptionBuilder.withDescription("Stop running NutchServer. "
            + "true value forces the Server to stop despite running jobs e.g. kills the tasks ");
    OptionBuilder.hasOptionalArg();
    OptionBuilder.withArgName("force");
    options.addOption(OptionBuilder.create(CMD_STOP));

    OptionBuilder.withDescription("Show this help");
    options.addOption(OptionBuilder.create(CMD_HELP));

    OptionBuilder.withDescription("Port to use for restful API.");
    OptionBuilder.hasOptionalArg();
    OptionBuilder.withArgName("port number");
    options.addOption(OptionBuilder.create(CMD_PORT));
    return options;
}

From source file:org.apache.nutch.scoring.webgraph.LinkDumper.java

/**
 * Runs the LinkDumper tool. This simply creates the database, to read the
 * values the nested Reader tool must be used.
 *///from   w  w w . j  av a  2s .c o  m
public int run(String[] args) throws Exception {

    Options options = new Options();
    OptionBuilder.withArgName("help");
    OptionBuilder.withDescription("show this help message");
    Option helpOpts = OptionBuilder.create("help");
    options.addOption(helpOpts);

    OptionBuilder.withArgName("webgraphdb");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("the web graph database to use");
    Option webGraphDbOpts = OptionBuilder.create("webgraphdb");
    options.addOption(webGraphDbOpts);

    CommandLineParser parser = new GnuParser();
    try {

        CommandLine line = parser.parse(options, args);
        if (line.hasOption("help") || !line.hasOption("webgraphdb")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("LinkDumper", options);
            return -1;
        }

        String webGraphDb = line.getOptionValue("webgraphdb");
        dumpLinks(new Path(webGraphDb));
        return 0;
    } catch (Exception e) {
        LOG.error("LinkDumper: " + StringUtils.stringifyException(e));
        return -2;
    }
}

From source file:org.apache.nutch.scoring.webgraph.LinkRank.java

/**
 * Runs the LinkRank tool./* w ww  .  ja  va  2 s .com*/
 */
public int run(String[] args) throws Exception {

    Options options = new Options();
    OptionBuilder.withArgName("help");
    OptionBuilder.withDescription("show this help message");
    Option helpOpts = OptionBuilder.create("help");
    options.addOption(helpOpts);

    OptionBuilder.withArgName("webgraphdb");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("the web graph db to use");
    Option webgraphOpts = OptionBuilder.create("webgraphdb");
    options.addOption(webgraphOpts);

    CommandLineParser parser = new GnuParser();
    try {

        CommandLine line = parser.parse(options, args);
        if (line.hasOption("help") || !line.hasOption("webgraphdb")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("LinkRank", options);
            return -1;
        }

        String webGraphDb = line.getOptionValue("webgraphdb");

        analyze(new Path(webGraphDb));
        return 0;
    } catch (Exception e) {
        LOG.error("LinkAnalysis: " + StringUtils.stringifyException(e));
        return -2;
    }
}

From source file:org.apache.nutch.scoring.webgraph.NodeDumper.java

/**
 * Runs the node dumper tool./*from  w  w w  .j  a  v  a 2 s  . c om*/
 */
public int run(String[] args) throws Exception {

    Options options = new Options();
    OptionBuilder.withArgName("help");
    OptionBuilder.withDescription("show this help message");
    Option helpOpts = OptionBuilder.create("help");
    options.addOption(helpOpts);

    OptionBuilder.withArgName("webgraphdb");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("the web graph database to use");
    Option webGraphDbOpts = OptionBuilder.create("webgraphdb");
    options.addOption(webGraphDbOpts);

    OptionBuilder.withArgName("inlinks");
    OptionBuilder.withDescription("show highest inlinks");
    Option inlinkOpts = OptionBuilder.create("inlinks");
    options.addOption(inlinkOpts);

    OptionBuilder.withArgName("outlinks");
    OptionBuilder.withDescription("show highest outlinks");
    Option outlinkOpts = OptionBuilder.create("outlinks");
    options.addOption(outlinkOpts);

    OptionBuilder.withArgName("scores");
    OptionBuilder.withDescription("show highest scores");
    Option scoreOpts = OptionBuilder.create("scores");
    options.addOption(scoreOpts);

    OptionBuilder.withArgName("topn");
    OptionBuilder.hasOptionalArg();
    OptionBuilder.withDescription("show topN scores");
    Option topNOpts = OptionBuilder.create("topn");
    options.addOption(topNOpts);

    OptionBuilder.withArgName("output");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("the output directory to use");
    Option outputOpts = OptionBuilder.create("output");
    options.addOption(outputOpts);

    OptionBuilder.withArgName("asEff");
    OptionBuilder.withDescription("Solr ExternalFileField compatible output format");
    Option effOpts = OptionBuilder.create("asEff");
    options.addOption(effOpts);

    OptionBuilder.hasArgs(2);
    OptionBuilder.withDescription("group <host|domain> <sum|max>");
    Option groupOpts = OptionBuilder.create("group");
    options.addOption(groupOpts);

    OptionBuilder.withArgName("asSequenceFile");
    OptionBuilder.withDescription("whether to output as a sequencefile");
    Option sequenceFileOpts = OptionBuilder.create("asSequenceFile");
    options.addOption(sequenceFileOpts);

    CommandLineParser parser = new GnuParser();
    try {

        CommandLine line = parser.parse(options, args);
        if (line.hasOption("help") || !line.hasOption("webgraphdb")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("NodeDumper", options);
            return -1;
        }

        String webGraphDb = line.getOptionValue("webgraphdb");
        boolean inlinks = line.hasOption("inlinks");
        boolean outlinks = line.hasOption("outlinks");

        long topN = (line.hasOption("topn") ? Long.parseLong(line.getOptionValue("topn")) : Long.MAX_VALUE);

        // get the correct dump type
        String output = line.getOptionValue("output");
        DumpType type = (inlinks ? DumpType.INLINKS : outlinks ? DumpType.OUTLINKS : DumpType.SCORES);

        NameType nameType = null;
        AggrType aggrType = null;
        String[] group = line.getOptionValues("group");
        if (group != null && group.length == 2) {
            nameType = (group[0].equals("host") ? NameType.HOST
                    : group[0].equals("domain") ? NameType.DOMAIN : null);
            aggrType = (group[1].equals("sum") ? AggrType.SUM : group[1].equals("sum") ? AggrType.MAX : null);
        }

        // Use ExternalFileField?
        boolean asEff = line.hasOption("asEff");
        boolean asSequenceFile = line.hasOption("asSequenceFile");

        dumpNodes(new Path(webGraphDb), type, topN, new Path(output), asEff, nameType, aggrType,
                asSequenceFile);
        return 0;
    } catch (Exception e) {
        LOG.error("NodeDumper: " + StringUtils.stringifyException(e));
        return -2;
    }
}

From source file:org.apache.nutch.scoring.webgraph.NodeReader.java

/**
 * Runs the NodeReader tool. The command line arguments must contain a
 * webgraphdb path and a url. The url must match the normalized url that is
 * contained in the NodeDb of the WebGraph.
 *///from www .j a v  a  2  s  .  c  om
public static void main(String[] args) throws Exception {

    Options options = new Options();
    OptionBuilder.withArgName("help");
    OptionBuilder.withDescription("show this help message");
    Option helpOpts = OptionBuilder.create("help");
    options.addOption(helpOpts);

    OptionBuilder.withArgName("webgraphdb");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("the webgraphdb to use");
    Option webGraphOpts = OptionBuilder.create("webgraphdb");
    options.addOption(webGraphOpts);

    OptionBuilder.withArgName("url");
    OptionBuilder.hasOptionalArg();
    OptionBuilder.withDescription("the url to dump");
    Option urlOpts = OptionBuilder.create("url");
    options.addOption(urlOpts);

    CommandLineParser parser = new GnuParser();
    try {

        // command line must take a webgraphdb and a url
        CommandLine line = parser.parse(options, args);
        if (line.hasOption("help") || !line.hasOption("webgraphdb") || !line.hasOption("url")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("WebGraphReader", options);
            return;
        }

        // dump the values to system out and return
        String webGraphDb = line.getOptionValue("webgraphdb");
        String url = line.getOptionValue("url");
        NodeReader reader = new NodeReader(NutchConfiguration.create());
        reader.dumpUrl(new Path(webGraphDb), url);

        return;
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }
}

From source file:org.apache.nutch.scoring.webgraph.ScoreUpdater.java

/**
 * Runs the ScoreUpdater tool.//from ww  w  .j  a va 2  s  . c  o m
 */
public int run(String[] args) throws Exception {

    Options options = new Options();
    OptionBuilder.withArgName("help");
    OptionBuilder.withDescription("show this help message");
    Option helpOpts = OptionBuilder.create("help");
    options.addOption(helpOpts);

    OptionBuilder.withArgName("crawldb");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("the crawldb to use");
    Option crawlDbOpts = OptionBuilder.create("crawldb");
    options.addOption(crawlDbOpts);

    OptionBuilder.withArgName("webgraphdb");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("the webgraphdb to use");
    Option webGraphOpts = OptionBuilder.create("webgraphdb");
    options.addOption(webGraphOpts);

    CommandLineParser parser = new GnuParser();
    try {

        CommandLine line = parser.parse(options, args);
        if (line.hasOption("help") || !line.hasOption("webgraphdb") || !line.hasOption("crawldb")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("ScoreUpdater", options);
            return -1;
        }

        String crawlDb = line.getOptionValue("crawldb");
        String webGraphDb = line.getOptionValue("webgraphdb");
        update(new Path(crawlDb), new Path(webGraphDb));
        return 0;
    } catch (Exception e) {
        LOG.error("ScoreUpdater: " + StringUtils.stringifyException(e));
        return -1;
    }
}

From source file:org.apache.nutch.service.NutchServer.java

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

    OptionBuilder.withDescription("Show this help");
    options.addOption(OptionBuilder.create(CMD_HELP));

    OptionBuilder.withArgName("port");
    OptionBuilder.hasOptionalArg();//from   w w  w .j  av a 2s. com
    OptionBuilder.withDescription("The port to run the Nutch Server. Default port 8081");
    options.addOption(OptionBuilder.create(CMD_PORT));

    OptionBuilder.withArgName("host");
    OptionBuilder.hasOptionalArg();
    OptionBuilder.withDescription("The host to bind the Nutch Server to. Default is localhost.");
    options.addOption(OptionBuilder.create(CMD_HOST));

    return options;
}

From source file:org.apache.nutch.tools.ResolveUrls.java

/**
 * Runs the resolve urls tool.//from   w  w  w .  ja v  a2 s.c  o  m
 */
public static void main(String[] args) {

    Options options = new Options();
    OptionBuilder.withArgName("help");
    OptionBuilder.withDescription("show this help message");
    Option helpOpts = OptionBuilder.create("help");
    options.addOption(helpOpts);

    OptionBuilder.withArgName("urls");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("the urls file to check");
    Option urlOpts = OptionBuilder.create("urls");
    options.addOption(urlOpts);

    OptionBuilder.withArgName("numThreads");
    OptionBuilder.hasArgs();
    OptionBuilder.withDescription("the number of threads to use");
    Option numThreadOpts = OptionBuilder.create("numThreads");
    options.addOption(numThreadOpts);

    CommandLineParser parser = new GnuParser();
    try {
        // parse out common line arguments
        CommandLine line = parser.parse(options, args);
        if (line.hasOption("help") || !line.hasOption("urls")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("ResolveUrls", options);
            return;
        }

        // get the urls and the number of threads and start the resolver
        String urls = line.getOptionValue("urls");
        int numThreads = 100;
        String numThreadsStr = line.getOptionValue("numThreads");
        if (numThreadsStr != null) {
            numThreads = Integer.parseInt(numThreadsStr);
        }
        ResolveUrls resolve = new ResolveUrls(urls, numThreads);
        resolve.resolveUrls();
    } catch (Exception e) {
        LOG.error("ResolveUrls: " + StringUtils.stringifyException(e));
    }
}