List of usage examples for org.apache.commons.cli OptionBuilder withArgName
public static OptionBuilder withArgName(String name)
From source file:com.google.oacurl.options.LoginOptions.java
@SuppressWarnings("static-access") public LoginOptions() { options.addOption(null, "buzz", false, "Use defaults for Buzz"); options.addOption(null, "blogger", false, "Use defaults for Blogger"); options.addOption(null, "latitude", false, "Use defaults for Latitude"); options.addOption("p", "service-provider", true, "properties file with service provider URLs (or GOOGLE, YAHOO, TWITTER, etc.)"); options.addOption("c", "consumer", true, "properties file with consumer key and secret"); options.addOption(OptionBuilder.withArgName("scope list").withLongOpt("scope").hasArg() .withDescription("Scopes (or BUZZ, BUZZ_READONLY, etc.)").create("s")); options.addOption("b", "browser", true, "Path to a browser to exec"); options.addOption(null, "nobrowser", false, "Don't use a browser at all, write URL to stdout"); options.addOption(null, "noserver", false, "Don't start the server, get token from stdin"); options.addOption(null, "consumer-key", true, "Consumer key (if file is not specified)"); options.addOption(null, "consumer-secret", true, "Consumer key (if file is not specified)"); options.addOption(null, "icon-url", true, "URL to an app icon to show on Buzz page"); options.addOption(null, "demo", false, "Loads a demo web-app for the login flow"); options.addOption(null, "host", true, "Sets a host to use besides localhost"); options.addOption(null, "callback", true, "Use a callback other than the auto-generated localhost one"); options.addOption(null, "wirelog", false, "Shows HTTP traffic for login requests"); options.addOption(OptionBuilder.withArgName("query parameter").withLongOpt("param").hasArg() .withDescription("Custom parameter to add to the authorization URL").create("P")); options.addOption("1", "oauth1.0a", false, "Use OAuth 1.0a (default)"); options.addOption("2", "oauth2", false, "Use OAuth 2"); options.addOption(null, "wrap", false, "Use OAuth-WRAP"); }
From source file:com.cloudera.sqoop.tool.MergeTool.java
/** * Construct the set of options that control imports, either of one * table or a batch of tables./* w w w .j a v a2s .c o m*/ * @return the RelatedOptions that can be used to parse the import * arguments. */ protected RelatedOptions getMergeOptions() { // Imports RelatedOptions mergeOpts = new RelatedOptions("Merge arguments"); mergeOpts.addOption(OptionBuilder.withArgName("file").hasArg() .withDescription("Load class from specified jar file").withLongOpt(JAR_FILE_NAME_ARG).create()); mergeOpts.addOption(OptionBuilder.withArgName("name").hasArg() .withDescription("Specify record class name to load").withLongOpt(CLASS_NAME_ARG).create()); mergeOpts.addOption(OptionBuilder.withArgName("path").hasArg() .withDescription("Path to the more recent data set").withLongOpt(NEW_DATASET_ARG).create()); mergeOpts.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("Path to the older data set") .withLongOpt(OLD_DATASET_ARG).create()); mergeOpts.addOption(OptionBuilder.withArgName("path").hasArg() .withDescription("Destination path for merged results").withLongOpt(TARGET_DIR_ARG).create()); mergeOpts.addOption(OptionBuilder.withArgName("column").hasArg() .withDescription("Key column to use to join results").withLongOpt(MERGE_KEY_ARG).create()); // Since the "common" options aren't used in the merge tool, // add these settings here. mergeOpts.addOption(OptionBuilder.withDescription("Print more information while working") .withLongOpt(VERBOSE_ARG).create()); mergeOpts.addOption( OptionBuilder.withDescription("Print usage instructions").withLongOpt(HELP_ARG).create()); return mergeOpts; }
From source file:com.google.code.uclassify.client.examples.ClassifierExample.java
/** * Build command line options object.//from w w w . j ava 2 s. c om * * @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 Write Key."; OptionBuilder.withArgName("readKey"); OptionBuilder.hasArg(); OptionBuilder.withDescription(consumerKeyMsg); Option consumerKey = OptionBuilder.create(WRITE_KEY); opts.addOption(consumerKey); String idMsg = "Classifier Name"; OptionBuilder.withArgName("classifier"); OptionBuilder.hasArg(); OptionBuilder.withDescription(idMsg); Option id = OptionBuilder.create(CLASSIFIER); opts.addOption(id); return opts; }
From source file:de.l3s.common.features.hadoop.TimeSeriesJob.java
@Override public int run(String[] args) throws Exception { Options opts = new Options(); Option jnameOpt = OptionBuilder.withArgName("job-name").hasArg(true).withDescription("Timeseries analysis") .create(JOB_NAME);/*from ww w . java 2 s. com*/ Option inputOpt = OptionBuilder.withArgName("input-path").hasArg(true) .withDescription("Timeseries file path (required)").create(INPUT_OPT); Option outputOpt = OptionBuilder.withArgName("output-path").hasArg(true) .withDescription("output file path (required)").create(OUTPUT_OPT); Option reduceOpt = OptionBuilder.withArgName("reduce-no").hasArg(true) .withDescription("number of reducer nodes").create(REDUCE_NO); Option rmOpt = OptionBuilder.withArgName("remove-out").hasArg(false) .withDescription("remove the output then create again before writing files onto it") .create(REMOVE_OUTPUT); Option cOpt = OptionBuilder.withArgName("compress-option").hasArg(true) .withDescription("compression option").create(COMPRESS_OPT); opts.addOption(jnameOpt); opts.addOption(inputOpt); opts.addOption(reduceOpt); opts.addOption(outputOpt); opts.addOption(rmOpt); opts.addOption(cOpt); CommandLine cl; CommandLineParser parser = new GnuParser(); try { cl = parser.parse(opts, args); } catch (ParseException e) { System.err.println("Error parsing command line: " + e.getMessage()); return -1; } if (!cl.hasOption(INPUT_OPT) || !cl.hasOption(OUTPUT_OPT)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(getClass().getName(), opts); ToolRunner.printGenericCommandUsage(System.out); return -1; } int reduceNo = DEFAULT_REDUCER_NO; if (cl.hasOption(REDUCE_NO)) { try { reduceNo = Integer.parseInt(cl.getOptionValue(REDUCE_NO)); } catch (NumberFormatException e) { System.err.println("Error parsing reducer number: " + e.getMessage()); } } String jobName = "Distributed timeseries [R] correlation"; if (cl.hasOption(JOB_NAME)) { jobName = cl.getOptionValue(JOB_NAME); jobName = jobName.replace('-', ' '); } if (cl.hasOption(REMOVE_OUTPUT)) { } String input = cl.getOptionValue(INPUT_OPT); String output = cl.getOptionValue(OUTPUT_OPT); Configuration conf = getConf(); //DistributedCache.createSymlink(conf); //DistributedCache.addCacheFile(new URI("hdfs://master.hadoop:8020/user/nguyen/lib/"), conf); Job job = Job.getInstance(conf, jobName); job.setJarByClass(TimeSeriesJob.class); job.setMapperClass(TimeSeriesMapper.class); job.setReducerClass(TimeSeriesReducer.class); job.setMapOutputKeyClass(Text.class); job.setMapOutputValueClass(Timeseries.class); job.setNumReduceTasks(reduceNo); job.setInputFormatClass(WholeFileInputFormat.class); WholeFileInputFormat.setInputPaths(job, input); FileOutputFormat.setOutputPath(job, new Path(output)); return job.waitForCompletion(true) ? 0 : 1; }
From source file:co.turnus.analysis.profiler.orcc.dynamic.OrccDynamicProfilerApplication.java
@SuppressWarnings("static-access") public OrccDynamicProfilerApplication() { workspace = ResourcesPlugin.getWorkspace(); cliOptions = new Options(); {// create all the options // verbosity cliOptions.addOption("v", false, "enable verbose mode"); // help console message cliOptions.addOption("h", false, "print the help message"); // Orcc CAL Project name Option o = OptionBuilder.withArgName("name").hasArg().withType(String.class) .withDescription("Orcc CAL project name").create("p"); o.isRequired();//from w w w . j a v a 2s .c o m cliOptions.addOption(o); // XDF file name o = OptionBuilder.withArgName("name").hasArg().withType(String.class) .withDescription("XDF top project network").create("x"); o.isRequired(); cliOptions.addOption(o); // input stimulus file file o = OptionBuilder.withArgName("file").hasArg().withType(String.class) .withDescription("input stimulus file").create("i"); cliOptions.addOption(o); // input stimulus file file o = OptionBuilder.withArgName("value").hasArg().withType(Integer.class) .withDescription("default buffer size").create("b"); cliOptions.addOption(o); // trace project name o = OptionBuilder.withArgName("name").hasArg().withType(String.class) .withDescription("generate a trace project with the given name").create("t"); cliOptions.addOption(o); // output path o = OptionBuilder.withArgName("path").hasArg().withType(String.class) .withDescription("define the output path").create("o"); o.isRequired(); cliOptions.addOption(o); // compress the execution trace cliOptions.addOption("z", false, "compress the execution trace graph file"); // store profiling data cliOptions.addOption("prof", false, "store profiling data. " + "(already enabled when the trace project is required)"); // store execution gantt chart cliOptions.addOption("gantt", false, "store the execution gantt chart"); // versioner name o = OptionBuilder.withArgName("name").hasArg().withType(String.class).withDescription("versioner name") .create("versioner"); cliOptions.addOption(o); // scheduler name o = OptionBuilder.withArgName("name").hasArg().withType(String.class).withDescription("scheduler name") .create("scheduler"); cliOptions.addOption(o); // type resize transformations o = OptionBuilder.withArgName("a,b,c").hasArgs(3).withType(Boolean.class) .withDescription("select the type resize transformations to use (true/false). \n" + "a: native ports\n" + "b: to 32 bit\n" + "c: to n bit") .create("resizer"); o.setValueSeparator(','); cliOptions.addOption(o); // stack protection cliOptions.addOption("stack-protector", false, "enable stack-protection for arrays load"); // code transformations o = OptionBuilder.withArgName("a,b,c,d,e,f").hasArgs(6).withType(Boolean.class) .withDescription("select the code transformations to use (true/false). \n" + "a: constant folding\n" + "b: constant propagation\n" + "c: dead actions\n" + "d: expression evaluation\n" + "e: dead code\n" + "f: variable initializer") .create("transfo"); o.setValueSeparator(','); cliOptions.addOption(o); } }
From source file:com.flaptor.indextank.storage.IndexesLogServer.java
@SuppressWarnings("static-access") private static Options getOptions() { Option rport = OptionBuilder.withArgName("reader_port").hasArg().withDescription("Server Port") .withLongOpt("reader_port").create("rp"); Option mport = OptionBuilder.withArgName("reader_port").hasArg().withDescription("Server Port") .withLongOpt("manager_port").create("mp"); Option help = OptionBuilder.withDescription("Displays this help").withLongOpt("help").create("h"); Options options = new Options(); options.addOption(rport);/*from w ww . j ava 2 s. c o m*/ options.addOption(mport); options.addOption(help); return options; }
From source file:edu.umd.cloud9.collection.trecweb.RepackTrecWebCollection.java
/** * Runs this tool./* ww w .ja 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("(required) collection path") .create(COLLECTION_OPTION)); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("(required) output path") .create(OUTPUT_OPTION)); options.addOption(OptionBuilder.withArgName("type").hasArg() .withDescription("(required) compression type: 'block', 'record', or 'none'") .create(COMPRESSION_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(COLLECTION_OPTION) || !cmdline.hasOption(OUTPUT_OPTION) || !cmdline.hasOption(COMPRESSION_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(this.getClass().getName(), options); ToolRunner.printGenericCommandUsage(System.out); return -1; } String collection = cmdline.getOptionValue(COLLECTION_OPTION); String output = cmdline.getOptionValue(OUTPUT_OPTION); String compressionType = cmdline.getOptionValue(COMPRESSION_OPTION); if (!compressionType.equals("block") && !compressionType.equals("record") && !compressionType.equals("none")) { System.err.println("Error: \"" + compressionType + "\" unknown compression type!"); System.exit(-1); } // This is the default block size. int blocksize = 1000000; Job job = new Job(getConf(), RepackTrecWebCollection.class.getSimpleName() + ":" + collection); FileSystem fs = FileSystem.get(job.getConfiguration()); job.setJarByClass(RepackTrecWebCollection.class); LOG.info("Tool name: " + RepackTrecWebCollection.class.getCanonicalName()); LOG.info(" - collection path: " + collection); LOG.info(" - output path: " + output); LOG.info(" - compression type: " + compressionType); if (compressionType.equals("block")) { LOG.info(" - block size: " + blocksize); } Path collectionPath = new Path(collection); for (FileStatus status : fs.listStatus(collectionPath)) { if (status.isDirectory()) { for (FileStatus s : fs.listStatus(status.getPath())) { FileInputFormat.addInputPath(job, s.getPath()); } } else { FileInputFormat.addInputPath(job, status.getPath()); } } // Hack to figure out number of reducers. int numReducers = 100; if (collection.toLowerCase().contains("wt10g")) { numReducers = 50; } else if (collection.toLowerCase().contains("gov2")) { numReducers = 200; } LOG.info(" - number of reducers: " + numReducers); job.setNumReduceTasks(numReducers); FileOutputFormat.setOutputPath(job, new Path(output)); if (compressionType.equals("none")) { SequenceFileOutputFormat.setCompressOutput(job, false); } else { SequenceFileOutputFormat.setCompressOutput(job, true); if (compressionType.equals("record")) { SequenceFileOutputFormat.setOutputCompressionType(job, SequenceFile.CompressionType.RECORD); } else { SequenceFileOutputFormat.setOutputCompressionType(job, SequenceFile.CompressionType.BLOCK); job.getConfiguration().setInt("io.seqfile.compress.blocksize", blocksize); } } job.setInputFormatClass(TrecWebDocumentInputFormat.class); job.setOutputFormatClass(SequenceFileOutputFormat.class); job.setOutputKeyClass(LongWritable.class); job.setOutputValueClass(TrecWebDocument.class); job.setMapperClass(MyMapper.class); // delete the output directory if it exists already fs.delete(new Path(output), true); try { job.waitForCompletion(true); } catch (Exception e) { throw new RuntimeException(e); } return 0; }
From source file:de.wpsverlinden.otrsspy.OtrsSpy.java
private void init(String[] args) { Options options = new Options(); options.addOption(OptionBuilder.withArgName("host").isRequired().hasArg() .withDescription("host running OTRS (e.g. \"http://company.intranet/otrs/\"").create("h")); options.addOption(OptionBuilder.withArgName("user").isRequired().hasArg() .withDescription("user of any valid oats agent").create("u")); options.addOption(OptionBuilder.withArgName("password").isRequired().hasArg() .withDescription("password of any valid oats agent").create("p")); options.addOption(OptionBuilder.withArgName("language").hasArg() .withDescription("language code of the OTRS instance (default: de)").create("l")); try {/*from w w w .j a va 2s . c om*/ CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); host = cmd.getOptionValue("h"); user = cmd.getOptionValue("u"); password = cmd.getOptionValue("p"); lang = cmd.hasOption("l") ? cmd.getOptionValue("l") : "de"; if (!host.endsWith("/")) { host = host.concat("/"); } } catch (ParseException pe) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar otrsspy", options, true); System.exit(0); } }
From source file:main.ReportGenerator.java
/** * Creates the options for the given arguments * @param args/*from w w w .j av a2s.com*/ * @return the CommandLine with the options */ @SuppressWarnings("static-access") public static CommandLine createOptions(String[] args) { CommandLine cmd = null; //create the options Options options = new Options(); options.addOption("h", "help", false, "prints the help content"); options.addOption(OptionBuilder.withArgName("json-file").hasArg() .withDescription("input file with the JSON").withLongOpt("input").create("i")); options.addOption(OptionBuilder.withArgName("file").hasArg() .withDescription("output directory (Default: ./)").withLongOpt("output").create("o")); options.addOption(OptionBuilder.withArgName("name").hasArg() .withDescription("output file name (witout extension)").withLongOpt("name").create("n")); options.addOption(OptionBuilder.withArgName("file").hasArg().isRequired().withDescription("template file") .withLongOpt("template").create("t")); options.addOption(new Option("pdf", "generate output in pdf format")); options.addOption( new Option("doc", "generate output in doc format (.odt or .docx, depend of the template format)")); options.addOption(new Option("html", "generate output in html format")); options.addOption(new Option("a", "all", false, "generate output in all format (default)")); //parse it try { CommandLineParser parser = new GnuParser(); cmd = parser.parse(options, args); } catch (MissingOptionException e) { displayHelp(options); System.exit(1); } catch (MissingArgumentException e) { displayHelp(options); System.exit(1); } catch (ParseException e) { System.err.println("Error while parsing the command line: " + e.getMessage()); System.exit(1); } catch (Exception e) { e.printStackTrace(); } return cmd; }
From source file:cc.twittertools.download.AsyncHTMLStatusBlockCrawler.java
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("data file with tweet ids") .create(DATA_OPTION));/*ww w. j ava 2 s . c o m*/ options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("output file (*.gz)") .create(OUTPUT_OPTION)); options.addOption(OptionBuilder.withArgName("path").hasArg() .withDescription("output repair file (can be used later as a data file)").create(REPAIR_OPTION)); options.addOption(NOFOLLOW_OPTION, NOFOLLOW_OPTION, false, "don't follow 301 redirects"); 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(DATA_OPTION) || !cmdline.hasOption(OUTPUT_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(AsyncHTMLStatusBlockCrawler.class.getName(), options); System.exit(-1); } String data = cmdline.getOptionValue(DATA_OPTION); String output = cmdline.getOptionValue(OUTPUT_OPTION); String repair = cmdline.getOptionValue(REPAIR_OPTION); boolean noFollow = cmdline.hasOption(NOFOLLOW_OPTION); new AsyncHTMLStatusBlockCrawler(new File(data), output, repair, noFollow).fetch(); }