List of usage examples for org.apache.commons.cli OptionBuilder create
public static Option create(String opt) throws IllegalArgumentException
char
. 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. *//* w w 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("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./* 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("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 ww w . j a va 2s. 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 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. *///www . ja v a2s. com 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 w w w.j ava 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("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 www . j av a 2s . c o m 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./* w w w . j a v a 2 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)); } }
From source file:org.apache.nutch.webui.NutchUiServer.java
private static Options createWebAppOptions() { Options options = new Options(); Option helpOpt = new Option("h", "help", false, "show this help message"); OptionBuilder.withDescription("Port to run the WebApplication on."); OptionBuilder.hasOptionalArg();/*from w w w . j a va2 s. co m*/ OptionBuilder.withArgName("port number"); options.addOption(OptionBuilder.create(CMD_PORT)); options.addOption(helpOpt); return options; }
From source file:org.apache.samza.tools.CommandLineHelper.java
public static Option createOption(String shortOpt, String longOpt, String argName, boolean required, String description) {/* w ww .java2 s . co m*/ OptionBuilder optionBuilder = OptionBuilder.withLongOpt(longOpt).withDescription(description) .isRequired(required); if (!StringUtils.isEmpty(argName)) { optionBuilder = optionBuilder.withArgName(argName).hasArg(); } return optionBuilder.create(shortOpt); }
From source file:org.apache.usergrid.launcher.Server.java
static Options createOptions() { // the nogui option will be required due to combining the graphical // launcher with this standalone CLI based server Options options = new Options(); OptionBuilder.withDescription("Start launcher without UI"); OptionBuilder.isRequired(true);/* ww w . ja v a2s . c om*/ Option noguiOption = OptionBuilder.create("nogui"); OptionBuilder.isRequired(false); OptionBuilder.withDescription("Initialize database"); Option initOption = OptionBuilder.create("init"); OptionBuilder.withDescription("Start database"); Option dbOption = OptionBuilder.create("db"); OptionBuilder.withDescription("Http port (without UI)"); OptionBuilder.hasArg(); OptionBuilder.withArgName("PORT"); OptionBuilder.withLongOpt("port"); OptionBuilder.withType(Number.class); Option portOption = OptionBuilder.create('p'); options.addOption(initOption); options.addOption(dbOption); options.addOption(portOption); options.addOption(noguiOption); return options; }