List of usage examples for org.apache.commons.cli OptionBuilder withArgName
public static OptionBuilder withArgName(String name)
From source file:com.google.code.uclassify.client.examples.ClassifyExample.java
/** * Build command line options object.// w w w . j a v a2 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 consumerKeyMsg = "You API Read Key."; OptionBuilder.withArgName("readKey"); OptionBuilder.hasArg(); OptionBuilder.withDescription(consumerKeyMsg); Option consumerKey = OptionBuilder.create(READ_KEY); opts.addOption(consumerKey); String idMsg = "Classifier Name"; OptionBuilder.withArgName("classifier"); OptionBuilder.hasArg(); OptionBuilder.withDescription(idMsg); Option id = OptionBuilder.create(CLASSIFIER); opts.addOption(id); String urlMsg = "Text to be classified."; OptionBuilder.withArgName("text"); OptionBuilder.hasArg(); OptionBuilder.withDescription(urlMsg); Option url = OptionBuilder.create(TEXT); opts.addOption(url); String typeMsg = "User who owns the classifier."; OptionBuilder.withArgName("user"); OptionBuilder.hasArg(); OptionBuilder.withDescription(typeMsg); Option type = OptionBuilder.create(USER); opts.addOption(type); return opts; }
From source file:FindMaxPageRankNodes.java
/** * Runs this tool./*from w w w. j a v a 2 s . c om*/ */ @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("top n").create(TOP)); 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) || !cmdline.hasOption(TOP)) { 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 n = Integer.parseInt(cmdline.getOptionValue(TOP)); LOG.info("Tool name: " + FindMaxPageRankNodes.class.getSimpleName()); LOG.info(" - input: " + inputPath); LOG.info(" - output: " + outputPath); LOG.info(" - top: " + n); Configuration conf = getConf(); conf.setInt("mapred.min.split.size", 1024 * 1024 * 1024); conf.setInt("n", n); Job job = Job.getInstance(conf); job.setJobName(FindMaxPageRankNodes.class.getName() + ":" + inputPath); job.setJarByClass(FindMaxPageRankNodes.class); job.setNumReduceTasks(1); 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(FloatWritable.class); job.setOutputKeyClass(IntWritable.class); job.setOutputValueClass(FloatWritable.class); job.setMapperClass(MyMapper.class); job.setReducerClass(MyReducer.class); // Delete the output directory if it exists already. FileSystem.get(conf).delete(new Path(outputPath), true); job.waitForCompletion(true); return 0; }
From source file:BooleanRetrievalCompressed.java
/** * Runs this tool.//w w w .ja va 2 s. co 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(LookupPostingsCompressed.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); } FileSystem fs = FileSystem.get(new Configuration()); initialize(indexPath, collectionPath, fs); String[] queries = { "outrageous fortune AND", "white rose AND", "means deceit AND", "white red OR rose AND pluck AND", "unhappy outrageous OR good your AND OR fortune AND" }; for (String q : queries) { System.out.println("Query: " + q); runQuery(q); System.out.println(""); } return 1; }
From source file:edu.umd.gorden2.BooleanRetrievalCompressed.java
/** * Runs this tool.//from w w w.ja v a 2s. com */ @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); } FileSystem fs = FileSystem.get(new Configuration()); initialize(indexPath, collectionPath, fs); String[] queries = { "outrageous fortune AND", "white rose AND", "means deceit AND", "white red OR rose AND pluck AND", "unhappy outrageous OR good your AND OR fortune AND" }; for (String q : queries) { System.out.println("Query: " + q); runQuery(q); System.out.println(""); } return 1; }
From source file:Corrector.Config.java
public static void parseOptions(String[] args) { Options options = new Options(); options.addOption(new Option("help", "print this message")); options.addOption(new Option("h", "print this message")); options.addOption(new Option("expert", "show expert options")); // work directories options.addOption(OptionBuilder.withArgName("hadoopBasePath").hasArg() .withDescription("Base Hadoop output directory [required]").create("out")); options.addOption(OptionBuilder.withArgName("hadoopReadPath").hasArg() .withDescription("Hadoop read directory [required]").create("in")); options.addOption(OptionBuilder.withArgName("workdir").hasArg() .withDescription("Local work directory (default: " + localBasePath + ")").create("work")); // hadoop options options.addOption(OptionBuilder.withArgName("numSlots").hasArg() .withDescription("Number of machine slots to use (default: " + HADOOP_MAPPERS + ")") .create("slots")); options.addOption(OptionBuilder.withArgName("childOpts").hasArg() .withDescription("Child Java Options (default: " + HADOOP_JAVAOPTS + ")").create("javaopts")); options.addOption(OptionBuilder.withArgName("millisecs").hasArg() .withDescription("Hadoop task timeout (default: " + HADOOP_TIMEOUT + ")").create("timeout")); // job restart options.addOption(//from w ww .j a v a 2s. c o m OptionBuilder.withArgName("stage").hasArg().withDescription("Starting stage").create("start")); options.addOption(OptionBuilder.withArgName("stage").hasArg().withDescription("Stop stage").create("stop")); options.addOption( OptionBuilder.withArgName("stage").hasArg().withDescription("Screening stage").create("screening")); // initial graph options.addOption(OptionBuilder.withArgName("read length").hasArg().withDescription("Read Length ") .create("readlen")); // randomize threshold options.addOption( OptionBuilder.withArgName("random pass").hasArg().withDescription("Random Pass ").create("random")); // kmer status options.addOption(OptionBuilder.withArgName("kmer upper bound").hasArg() .withDescription("max kmer cov (default: " + UP_KMER).create("kmerup")); options.addOption(OptionBuilder.withArgName("kmer lower bound").hasArg() .withDescription("min kmer cov (default: " + LOW_KMER).create("kmerlow")); CommandLineParser parser = new GnuParser(); try { CommandLine line = parser.parse(options, args); if (line.hasOption("help") || line.hasOption("h") || line.hasOption("expert")) { System.out.print( "Usage: hadoop jar ReadStackCorrector.jar [-in dir] [-out dir] [-readlen readlen] [options]\n" + "\n" + "General Options:\n" + "===============\n" + " -out <outdir> : Output directory for corrected reads [required]\n" + " -in <indir> : Directory with reads [required]\n" + " -work <workdir> : Local directory for log files [" + localBasePath + "]\n" + " -slots <slots> : Hadoop Slots to use [" + HADOOP_MAPPERS + "]\n" + " -screening <on/off> : Switch of Screening Phase\n" + " -expert : Show expert options\n"); if (line.hasOption("expert")) { System.out.print(" -kmerup <coverage> : Read stack upper bound [500]\n" + //" -kmerlow <coveage> : Kmer coverage lower bound [1]\n" + " -random <pass rate> : Randomized pass message [100]\n" + "\n" + "Hadoop Options:\n" + "===============\n" + " -javaopts <opts> : Hadoop Java Opts [" + HADOOP_JAVAOPTS + "]\n" + " -timeout <usec> : Hadoop task timeout [" + HADOOP_TIMEOUT + "]\n" + "\n"); } System.exit(0); } if (line.hasOption("out")) { hadoopBasePath = line.getOptionValue("out"); } if (line.hasOption("in")) { hadoopReadPath = line.getOptionValue("in"); } if (line.hasOption("work")) { localBasePath = line.getOptionValue("work"); } if (line.hasOption("slots")) { HADOOP_MAPPERS = Integer.parseInt(line.getOptionValue("slots")); HADOOP_REDUCERS = HADOOP_MAPPERS; } if (line.hasOption("nodes")) { HADOOP_LOCALNODES = Integer.parseInt(line.getOptionValue("nodes")); } if (line.hasOption("javaopts")) { HADOOP_JAVAOPTS = line.getOptionValue("javaopts"); } if (line.hasOption("timeout")) { HADOOP_TIMEOUT = Long.parseLong(line.getOptionValue("timeout")); } if (line.hasOption("readlen")) { READLEN = Long.parseLong(line.getOptionValue("readlen")); } if (line.hasOption("kmerup")) { UP_KMER = Long.parseLong(line.getOptionValue("kmerup")); } if (line.hasOption("random")) { RANDOM_PASS = Long.parseLong(line.getOptionValue("random")); } if (line.hasOption("start")) { STARTSTAGE = line.getOptionValue("start"); } if (line.hasOption("stop")) { STOPSTAGE = line.getOptionValue("stop"); } if (line.hasOption("screening")) { SCREENING = line.getOptionValue("screening"); } } catch (ParseException exp) { System.err.println("Parsing failed. Reason: " + exp.getMessage()); System.exit(1); } }
From source file:ca.uqac.info.trace.generation.TraceGenerator.java
/** * Creates the proper command line options to gather parameters * relevant to the configuration of the trace generator. This * method must be implemented by all trace generators, in order * for them to declare their command line switches. * @return The Options object containing the options required by * this generator/* ww w . jav a2s. c o m*/ */ @SuppressWarnings("static-access") public Options getCommandLineOptions() { Options options = new Options(); Option opt; options.addOption("t", false, "Use system clock as random generator's seed (default: no)"); opt = OptionBuilder.withArgName("x").hasArg() .withDescription("Set random generator's seed to x (default: 0)").create("s"); options.addOption(opt); opt = OptionBuilder.withArgName("x").hasArg() .withDescription("Maximum number of messages to produce (default: 10)").create("N"); options.addOption(opt); opt = OptionBuilder.withArgName("x").hasArg() .withDescription("Minimum number of messages to produce (default: 1)").create("n"); options.addOption(opt); opt = OptionBuilder.withArgName("x").hasArg() .withDescription("Maximum number of tags to produce (default: 1)").create("M"); options.addOption(opt); opt = OptionBuilder.withArgName("x").hasArg() .withDescription("Set verbosity level to x (default: 0 = no messages)").withLongOpt("verbose") .create(); options.addOption(opt); return options; }
From source file:com.engineering.ses.spell.clientstubj.cmdclient.CommandClient.java
/*************************************************************************** * Constructor// w w w . j a v a 2 s . c o m **************************************************************************/ @SuppressWarnings("static-access") public CommandClient() { m_listener = new ListenerInterface(); m_context = new ContextInterface(); m_cmdProcessor = new CommandProcessor(m_listener, m_context); m_options = null; m_optionsDef = new Options(); m_optionsDef.addOption(OptionBuilder.withArgName("h").withLongOpt(OPT_HOSTNAME) .withDescription("host name of the SPELL server (required)").hasArg().withType(new String()) .isRequired().create()); m_optionsDef.addOption(OptionBuilder.withArgName("p").withLongOpt(OPT_PORT) .withDescription("port of the SPELL server (required)").hasArg().withType(new Integer(0)) .isRequired().create()); m_optionsDef.addOption(OptionBuilder.withArgName("c").withLongOpt(OPT_CONTEXT) .withDescription("name of the SPELL context (required)").hasArg().withType(new String()) .isRequired().create()); m_optionsDef.addOption(OptionBuilder.withArgName("e").withLongOpt(OPT_EXEC) .withDescription("list of commands to executed separated by ';'").isRequired(false) .withType(new String()).hasArg().create()); }
From source file:at.newmedialab.ldpath.backend.linkeddata.LDQuery.java
private static Options buildOptions() { Options result = new Options(); OptionGroup query = new OptionGroup(); Option path = OptionBuilder.withArgName("path").hasArg() .withDescription("LD Path to evaluate on the file starting from the context").create("path"); Option program = OptionBuilder.withArgName("file").hasArg() .withDescription("LD Path program to evaluate on the file starting from the context") .create("program"); query.addOption(path);//w ww .j a v a2s.c o m query.addOption(program); query.setRequired(true); result.addOptionGroup(query); Option context = OptionBuilder.withArgName("uri").hasArg() .withDescription("URI of the context node to start from").create("context"); context.setRequired(true); result.addOption(context); Option loglevel = OptionBuilder.withArgName("level").hasArg() .withDescription("set the log level; default is 'warn'").create("loglevel"); result.addOption(loglevel); Option store = OptionBuilder.withArgName("dir").hasArg() .withDescription("cache the retrieved data in this directory").create("store"); result.addOption(store); return result; }
From source file:edu.umd.JBizz.ExtractTopPersonalizedPageRankNodes.java
/** * Runs this tool./*from w w w. j a va2 s. co 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("top n").create(TOP)); 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) || !cmdline.hasOption(TOP)) { 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 n = Integer.parseInt(cmdline.getOptionValue(TOP)); LOG.info("Tool name: " + ExtractTopPersonalizedPageRankNodes.class.getSimpleName()); LOG.info(" - input: " + inputPath); LOG.info(" - output: " + outputPath); LOG.info(" - top: " + n); Configuration conf = getConf(); conf.setInt("mapred.min.split.size", 1024 * 1024 * 1024); conf.setInt("n", n); Job job = Job.getInstance(conf); job.setJobName(ExtractTopPersonalizedPageRankNodes.class.getName() + ":" + inputPath); job.setJarByClass(ExtractTopPersonalizedPageRankNodes.class); job.setNumReduceTasks(1); 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(FloatWritable.class); job.setOutputKeyClass(IntWritable.class); job.setOutputValueClass(FloatWritable.class); job.setMapperClass(MyMapper.class); job.setReducerClass(MyReducer.class); // Delete the output directory if it exists already. FileSystem.get(conf).delete(new Path(outputPath), true); job.waitForCompletion(true); return 0; }
From source file:checkchansourcedata.CheckChanSourceData.java
boolean parseCommand(String[] args, String programName, String version) { boolean ret = true; 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(OptionBuilder.withArgName("server").hasArg().withDescription("limit to server only") .create("server")); options.addOption(OptionBuilder.withArgName("chantype").hasArg() .withDescription("limit to this channel type only").create("chantype")); CommandLineParser parser = new GnuParser(); boolean wantHelp = false; CommandLine line;//w w w .ja v a2 s . c om 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"); if (line.hasOption("server")) { server = line.getOptionValue("server"); } else { server = ""; } if (line.hasOption("chantype")) { chantype = line.getOptionValue("chantype"); } else { chantype = ""; } } if (wantHelp) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(programName, options); ret = false; } return ret; }