List of usage examples for org.apache.commons.cli OptionBuilder withArgName
public static OptionBuilder withArgName(String name)
From source file:basic.PartitionGraph.java
/** * Runs this tool./*w ww .ja va2 s. com*/ */ @SuppressWarnings({ "static-access" }) public int run(String[] args) throws Exception { Options options = new Options(); options.addOption(new Option(RANGE, "use range partitioner")); 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("number of nodes").create(NUM_NODES)); options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("number of partitions") .create(NUM_PARTITIONS)); 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(NUM_NODES) || !cmdline.hasOption(NUM_PARTITIONS)) { 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 inPath = cmdline.getOptionValue(INPUT); String outPath = cmdline.getOptionValue(OUTPUT); int nodeCount = Integer.parseInt(cmdline.getOptionValue(NUM_NODES)); int numParts = Integer.parseInt(cmdline.getOptionValue(NUM_PARTITIONS)); boolean useRange = cmdline.hasOption(RANGE); LOG.info("Tool name: " + PartitionGraph.class.getSimpleName()); LOG.info(" - input dir: " + inPath); LOG.info(" - output dir: " + outPath); LOG.info(" - num partitions: " + numParts); LOG.info(" - node cnt: " + nodeCount); LOG.info(" - use range partitioner: " + useRange); Configuration conf = getConf(); conf.setInt("NodeCount", nodeCount); Job job = Job.getInstance(conf); job.setJobName(PartitionGraph.class.getSimpleName() + ":" + inPath); job.setJarByClass(PartitionGraph.class); job.setNumReduceTasks(numParts); FileInputFormat.setInputPaths(job, new Path(inPath)); FileOutputFormat.setOutputPath(job, new Path(outPath)); job.setInputFormatClass(NonSplitableSequenceFileInputFormat.class); job.setOutputFormatClass(SequenceFileOutputFormat.class); job.setMapOutputKeyClass(IntWritable.class); job.setMapOutputValueClass(PageRankNode.class); job.setOutputKeyClass(IntWritable.class); job.setOutputValueClass(PageRankNode.class); if (useRange) { job.setPartitionerClass(RangePartitioner.class); } FileSystem.get(conf).delete(new Path(outPath), true); job.waitForCompletion(true); return 0; }
From source file:edu.umd.gorden2.PartitionGraph.java
/** * Runs this tool./*from ww w.j av a2 s . c o m*/ */ @SuppressWarnings({ "static-access" }) public int run(String[] args) throws Exception { Options options = new Options(); options.addOption(new Option(RANGE, "use range partitioner")); 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("number of nodes").create(NUM_NODES)); options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("number of partitions") .create(NUM_PARTITIONS)); 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(NUM_NODES) || !cmdline.hasOption(NUM_PARTITIONS)) { 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 inPath = cmdline.getOptionValue(INPUT); String outPath = cmdline.getOptionValue(OUTPUT); int nodeCount = Integer.parseInt(cmdline.getOptionValue(NUM_NODES)); int numParts = Integer.parseInt(cmdline.getOptionValue(NUM_PARTITIONS)); boolean useRange = cmdline.hasOption(RANGE); LOG.info("Tool name: " + PartitionGraph.class.getSimpleName()); LOG.info(" - input dir: " + inPath); LOG.info(" - output dir: " + outPath); LOG.info(" - num partitions: " + numParts); LOG.info(" - node cnt: " + nodeCount); LOG.info(" - use range partitioner: " + useRange); Configuration conf = getConf(); conf.setInt("NodeCount", nodeCount); Job job = Job.getInstance(conf); job.setJobName(PartitionGraph.class.getSimpleName() + ":" + inPath); job.setJarByClass(PartitionGraph.class); job.setNumReduceTasks(numParts); FileInputFormat.setInputPaths(job, new Path(inPath)); FileOutputFormat.setOutputPath(job, new Path(outPath)); job.setInputFormatClass(NonSplitableSequenceFileInputFormat.class); job.setOutputFormatClass(SequenceFileOutputFormat.class); job.setMapOutputKeyClass(IntWritable.class); job.setMapOutputValueClass(PageRankNode.class); job.setOutputKeyClass(IntWritable.class); job.setOutputValueClass(PageRankNode.class); //if (useRange) { //job.setPartitionerClass(RangePartitioner.class); //} FileSystem.get(conf).delete(new Path(outPath), true); job.waitForCompletion(true); return 0; }
From source file:edu.umd.shrawanraina.PartitionGraph.java
/** * Runs this tool./*from w w w .j a v a 2s . com*/ */ @SuppressWarnings({ "static-access" }) public int run(String[] args) throws Exception { Options options = new Options(); options.addOption(new Option(RANGE, "use range partitioner")); 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("number of nodes").create(NUM_NODES)); options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("number of partitions") .create(NUM_PARTITIONS)); 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(NUM_NODES) || !cmdline.hasOption(NUM_PARTITIONS)) { 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 inPath = cmdline.getOptionValue(INPUT); String outPath = cmdline.getOptionValue(OUTPUT); int nodeCount = Integer.parseInt(cmdline.getOptionValue(NUM_NODES)); int numParts = Integer.parseInt(cmdline.getOptionValue(NUM_PARTITIONS)); boolean useRange = cmdline.hasOption(RANGE); LOG.info("Tool name: " + PartitionGraph.class.getSimpleName()); LOG.info(" - input dir: " + inPath); LOG.info(" - output dir: " + outPath); LOG.info(" - num partitions: " + numParts); LOG.info(" - node cnt: " + nodeCount); LOG.info(" - use range partitioner: " + useRange); Configuration conf = getConf(); conf.setInt("NodeCount", nodeCount); Job job = Job.getInstance(conf); job.setJobName(PartitionGraph.class.getSimpleName() + ":" + inPath); job.setJarByClass(PartitionGraph.class); job.setNumReduceTasks(numParts); FileInputFormat.setInputPaths(job, new Path(inPath)); FileOutputFormat.setOutputPath(job, new Path(outPath)); job.setInputFormatClass(NonSplitableSequenceFileInputFormat.class); job.setOutputFormatClass(SequenceFileOutputFormat.class); job.setMapOutputKeyClass(IntWritable.class); job.setMapOutputValueClass(PageRankNodeUpd.class); job.setOutputKeyClass(IntWritable.class); job.setOutputValueClass(PageRankNodeUpd.class); if (useRange) { job.setPartitionerClass(RangePartitioner.class); } FileSystem.get(conf).delete(new Path(outPath), true); job.waitForCompletion(true); return 0; }
From source file:jlite.cli.ProxyInit.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("h:m") .withDescription("proxy and AC are valid for h hours and m minutes (defaults to 12:00)").hasArg() .create("valid")); options.addOption(OptionBuilder.withDescription("creates a limited proxy").create("limited")); options.addOption(OptionBuilder.withArgName("version") .withDescription("version of proxy certificate {2,3,4} (default is 2)").hasArg() .create("proxyver")); options.addOption(OptionBuilder/*from w w w . j ava2s .c om*/ .withDescription("creates RFC 3820 compliant proxy (synonomous with -proxyver 4)").create("rfc")); options.addOption(OptionBuilder.withArgName("proxyfile") .withDescription("non-standard location of new proxy cert").hasArg().create("out")); options.addOption(OptionBuilder.withArgName("path") .withDescription("non-standard location of VOMS configuration files").hasArg().create("vomses")); options.addOption(OptionBuilder.withArgName("key") .withDescription("set your private key passphrase without any prompt").hasArg().create("password")); options.addOption(OptionBuilder.withArgName("xml").withDescription("output as xml").create("xml")); return options; }
From source file:es.ua.alex952.main.MainBatch.java
/** * Main constructor that parses all arguments from the command line * /*from w ww.j av a 2s. co m*/ * @param args Command line arguments */ public MainBatch(String[] args) { //Operation creation for usage print Option create = OptionBuilder.withLongOpt("create").withDescription("switch for creating a job") .create("c"); Option daemon = OptionBuilder.withArgName("id").withLongOpt("daemon") .withDescription("daemon mode for monitorizing the job after its creation").hasOptionalArg() .create("d"); Option configfile = OptionBuilder.withArgName("config.properties").withLongOpt("configfile") .withDescription("the properties config file that has all the program specific configurations") .hasArg().create("cf"); Option parametersfile = OptionBuilder.withArgName("parameters.properties").withLongOpt("parametersfile") .withDescription( "properties paramters file that has all the job specific parameters for its creation") .hasArg().create("pf"); Option sourcelanguage = OptionBuilder.withArgName("sl.txt").withLongOpt("sourcelanguage") .withDescription("text file containing all the sentences to be translated").hasArg().create("sl"); Option referencetranslations = OptionBuilder.withArgName("rt.txt").withLongOpt("referencetranslations") .withDescription("text file with a translation of reference for each source language sentence") .hasArg().create("rt"); Option gold = OptionBuilder.withArgName("gold.txt").withLongOpt("gold").withDescription( "text file with the gold standards given for the job. It has a three lines format that is composed by one line for the source language sentence, one for the reference translation, and the last one for the correct translation") .hasArg().create("g"); Option daemonfrecuency = OptionBuilder.withArgName("daemon frecuency").withLongOpt("daemonfrecuency") .withDescription("daemon check frecuency").hasArg().create("df"); Option help = OptionBuilder.withLongOpt("help").withDescription("shows this help message").create("h"); options.addOption(create); options.addOption(daemon); options.addOption(daemonfrecuency); options.addOption(configfile); options.addOption(parametersfile); options.addOption(sourcelanguage); options.addOption(referencetranslations); options.addOption(gold); options.addOption(help); //Option parsing CommandLineParser clp = new BasicParser(); try { CommandLine cl = clp.parse(options, args); if (cl.hasOption("help") || cl.getOptions().length == 0) { HelpFormatter hf = new HelpFormatter(); hf.setWidth(100); hf.printHelp("CrowdFlowerTasks", options); op = Operation.QUIT; return; } if (cl.hasOption("daemon") && !cl.hasOption("c")) { if (cl.getOptionValue("daemon") == null) { logger.error("The daemon option must have a job id if it isn't along with create option"); op = Operation.QUIT; return; } else if (!cl.hasOption("configfile")) { logger.error("The config file is mandatory"); op = Operation.QUIT; return; } try { Integer.parseInt(cl.getOptionValue("daemon")); this.id = cl.getOptionValue("daemon"); this.configFile = cl.getOptionValue("configfile"); this.op = Operation.DAEMON; if (cl.hasOption("daemonfrecuency")) { try { Long l = Long.parseLong(id); this.frecuency = l; } catch (NumberFormatException e) { this.logger.info("The frecuency is not a number. Setting to default: 10 sec"); } } else { this.logger.info("Daemon frecuency not set. Setting to default: 10 sec"); } } catch (NumberFormatException e) { this.logger.error("The id following daemon option must be an integer"); this.op = Operation.QUIT; return; } } else { if (!cl.hasOption("gold") || !cl.hasOption("configfile") || !cl.hasOption("parametersfile") || !cl.hasOption("referencetranslations") || !cl.hasOption("sourcelanguage")) { logger.error( "The files gold, tr, lo, config.properties and parameters.properties are mandatory for creating jobs"); this.op = Operation.QUIT; return; } else { if (cl.hasOption("daemon")) this.daemon = true; else { if (cl.hasOption("daemonfrecuency")) this.logger.info( "Daemon frecuency parameter found, ignoring it as there's not a daemon option"); } this.configFile = cl.getOptionValue("configfile"); this.parametersFile = cl.getOptionValue("parametersfile"); this.pathGold = cl.getOptionValue("gold"); this.pathLO = cl.getOptionValue("sourcelanguage"); this.pathTR = cl.getOptionValue("referencetranslations"); this.op = Operation.CREATE; } } } catch (ParseException ex) { logger.error("Failed argument parsing", ex); } }
From source file:android.example.hlsmerge.crypto.Main.java
private static CommandLine parseCommandLine(String[] args) { CommandLineParser parser = new PosixParser(); CommandLine commandLine = null;//from w w w. j a va2 s . co m Option help = new Option(OPT_HELP, "help", false, "print this message."); Option silent = new Option(OPT_SILENT, "silent", false, "silent mode."); Option overwrite = new Option(OPT_OVERWRITE, false, "overwrite output files."); Option key = OptionBuilder.withArgName(ARG_KEY).withLongOpt(OPT_KEY_LONG).hasArg() .withDescription("force use of the supplied AES-128 key.").create(OPT_KEY); Option outFile = OptionBuilder.withArgName(ARG_OUT_FILE).withLongOpt(OPT_OUT_FILE_LONG).hasArg() .withDescription("join all transport streams to one file.").create(OPT_OUT_FILE); Options options = new Options(); options.addOption(help); options.addOption(silent); options.addOption(overwrite); options.addOption(key); options.addOption(outFile); try { commandLine = parser.parse(options, args); if (commandLine.hasOption(OPT_HELP) || (commandLine.getArgs().length < 1)) { new HelpFormatter().printHelp(CLI_SYNTAX, options); System.exit(0); } if (commandLine.hasOption(OPT_KEY)) { String optKey = commandLine.getOptionValue(OPT_KEY); if (!optKey.matches("[0-9a-fA-F]{32}")) { System.out.printf( "Bad key format: \"%s\". Expected 32-character hex format.\nExample: -key 12ba7f70db4740dec4aab4c5c2c768d9", optKey); System.exit(1); } } } catch (ParseException e) { System.out.println(e.getMessage()); new HelpFormatter().printHelp(CLI_SYNTAX, options); System.exit(1); } return commandLine; }
From source file:com.cloudera.sqoop.tool.CreateHiveTableTool.java
@Override /** Configure the command-line arguments we expect to receive */ public void configureOptions(ToolOptions toolOptions) { toolOptions.addUniqueOptions(getCommonOptions()); RelatedOptions hiveOpts = getHiveOptions(false); hiveOpts.addOption(OptionBuilder.withArgName("table-name").hasArg() .withDescription("The db table to read the definition from").withLongOpt(TABLE_ARG).create()); toolOptions.addUniqueOptions(hiveOpts); toolOptions.addUniqueOptions(getOutputFormatOptions()); }
From source file:com.github.joemcintyre.pdffinish.Main.java
/** * Populate command line options, making available for command line * processing and usage message functions. *///from w w w. j a v a2 s .c om private static void populateOptions() { options = new Options(); options.addOption("s", "show", false, "Show PDF metadata and ToC"); options.addOption("v", "version", false, "Show version number"); options.addOption("h", "help", false, "Print this message"); OptionBuilder.withArgName("inputFile"); OptionBuilder.hasArg(); OptionBuilder.withDescription("input PDF file"); options.addOption(OptionBuilder.create("i")); OptionBuilder.withArgName("outputFile"); OptionBuilder.hasArg(); OptionBuilder.withDescription("output PDF file"); options.addOption(OptionBuilder.create("o")); OptionBuilder.withArgName("configFile"); OptionBuilder.hasArg(); OptionBuilder.withDescription("configuration file (JSON)"); options.addOption(OptionBuilder.create("c")); }
From source file:edu.umd.honghongie.PartitionGraph.java
/** * Runs this tool./*from w w w . j av a 2 s . c o m*/ */ @SuppressWarnings({ "static-access" }) public int run(String[] args) throws Exception { Options options = new Options(); options.addOption(new Option(RANGE, "use range partitioner")); 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("number of nodes").create(NUM_NODES)); options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("number of partitions") .create(NUM_PARTITIONS)); 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(NUM_NODES) || !cmdline.hasOption(NUM_PARTITIONS)) { 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 inPath = cmdline.getOptionValue(INPUT); String outPath = cmdline.getOptionValue(OUTPUT); int nodeCount = Integer.parseInt(cmdline.getOptionValue(NUM_NODES)); int numParts = Integer.parseInt(cmdline.getOptionValue(NUM_PARTITIONS)); boolean useRange = cmdline.hasOption(RANGE); LOG.info("Tool name: " + PartitionGraph.class.getSimpleName()); LOG.info(" - input dir: " + inPath); LOG.info(" - output dir: " + outPath); LOG.info(" - num partitions: " + numParts); LOG.info(" - node cnt: " + nodeCount); LOG.info(" - use range partitioner: " + useRange); Configuration conf = getConf(); conf.setInt("NodeCount", nodeCount); Job job = Job.getInstance(conf); job.setJobName(PartitionGraph.class.getSimpleName() + ":" + inPath); job.setJarByClass(PartitionGraph.class); job.setNumReduceTasks(numParts); FileInputFormat.setInputPaths(job, new Path(inPath)); FileOutputFormat.setOutputPath(job, new Path(outPath)); job.setInputFormatClass(NonSplitableSequenceFileInputFormat.class); job.setOutputFormatClass(SequenceFileOutputFormat.class); job.setMapOutputKeyClass(IntWritable.class); job.setMapOutputValueClass(PageRankNode.class); job.setOutputKeyClass(IntWritable.class); // job.setOutputKeyClass(LongWritable.class); job.setOutputValueClass(PageRankNode.class); if (useRange) { job.setPartitionerClass(RangePartitioner.class); } FileSystem.get(conf).delete(new Path(outPath), true); job.waitForCompletion(true); return 0; }
From source file:com.fatwire.dta.sscrawler.App.java
@SuppressWarnings("static-access") public static Options setUpCmd() { final Options options = new Options(); options.addOption("h", "help", false, "print this message."); final Option reportDir = OptionBuilder.withArgName("dir").hasArg() .withDescription("Directory where reports are stored").withLongOpt("reportDir").create("d"); options.addOption(reportDir);// w ww . jav a 2 s . c o m final Option max = OptionBuilder.withArgName("num").hasArg() .withDescription("Maximum number of pages, default is unlimited").withLongOpt("max").create("m"); options.addOption(max); final Option uriHelperFactory = OptionBuilder.withArgName("classname").hasArg() .withDescription("Class for constructing urls").withLongOpt("uriHelperFactory").create("f"); uriHelperFactory.setType(UriHelperFactory.class); options.addOption(uriHelperFactory); final Option threads = OptionBuilder.withArgName("num").hasArg() .withDescription("Number of concurrent threads that are reading from ContentServer") .withLongOpt("threads").create("t"); options.addOption(threads); final Option proxyUsername = OptionBuilder.withArgName("username").hasArg() .withDescription("Proxy Username").withLongOpt("proxyUsername").create("pu"); options.addOption(proxyUsername); final Option proxyPassword = OptionBuilder.withArgName("password").hasArg() .withDescription("Proxy Password").withLongOpt("proxyPassword").create("pw"); options.addOption(proxyPassword); final Option proxyHost = OptionBuilder.withArgName("host").hasArg().withDescription("Proxy hostname") .withLongOpt("proxyHost").create("ph"); options.addOption(proxyHost); final Option proxyPort = OptionBuilder.withArgName("port").hasArg().withDescription("Proxy port number") .withLongOpt("proxyPort").create("pp"); options.addOption(proxyPort); return options; }