List of usage examples for org.apache.commons.cli OptionBuilder withArgName
public static OptionBuilder withArgName(String name)
From source file:de.clusteval.data.randomizer.DataRandomizer.java
/** * Adds the default options of dataset generators to the given Options * attribute/*from w w w.ja v a 2 s . c o m*/ * * @param options * The existing Options attribute, holding already the options of * the actual generator implementation. */ private void addDefaultOptions(final Options options) { OptionBuilder.withArgName("dataConfig"); OptionBuilder.isRequired(); OptionBuilder.hasArg(); OptionBuilder.withDescription("The name of the data configuration to randomize"); Option option = OptionBuilder.create("dataConfig"); options.addOption(option); }
From source file:BuildPersonalizedPageRankRecords.java
/** * Runs this tool./*from w w w. j a v a2 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("number of nodes").create(NUM_NODES)); options.addOption( OptionBuilder.withArgName("sources").hasArg().withDescription("source nodes").create(SOURCES)); 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(SOURCES)) { 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(NUM_NODES)); String sources = cmdline.getOptionValue(SOURCES); LOG.info("Tool name: " + BuildPersonalizedPageRankRecords.class.getSimpleName()); LOG.info(" - inputDir: " + inputPath); LOG.info(" - outputDir: " + outputPath); LOG.info(" - numNodes: " + n); LOG.info(" - sources: " + sources); Configuration conf = getConf(); conf.setInt(NODE_CNT_FIELD, n); conf.setInt("mapred.min.split.size", 1024 * 1024 * 1024); conf.setStrings("sources", sources); Job job = Job.getInstance(conf); job.setJobName(BuildPersonalizedPageRankRecords.class.getSimpleName() + ":" + inputPath); job.setJarByClass(BuildPersonalizedPageRankRecords.class); job.setNumReduceTasks(0); FileInputFormat.addInputPath(job, new Path(inputPath)); FileOutputFormat.setOutputPath(job, new Path(outputPath)); job.setInputFormatClass(TextInputFormat.class); job.setOutputFormatClass(SequenceFileOutputFormat.class); job.setMapOutputKeyClass(IntWritable.class); job.setMapOutputValueClass(PageRankNodeExtended.class); job.setOutputKeyClass(IntWritable.class); job.setOutputValueClass(PageRankNodeExtended.class); job.setMapperClass(MyMapper.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:edu.umd.cloud9.collection.wikipedia.WikipediaDocnoMappingBuilder.java
@SuppressWarnings("static-access") @Override//w w w.j a v a2 s. c o m public int run(String[] args) throws Exception { Options options = new Options(); options.addOption( OptionBuilder.withArgName("path").hasArg().withDescription("XML dump file").create(INPUT_OPTION)); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("output file") .create(OUTPUT_FILE_OPTION)); options.addOption(OptionBuilder.withArgName("en|sv|de|cs|es|zh|ar|tr").hasArg() .withDescription("two-letter language code").create(LANGUAGE_OPTION)); options.addOption(KEEP_ALL_OPTION, false, "keep all pages"); 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_OPTION) || !cmdline.hasOption(OUTPUT_FILE_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(this.getClass().getName(), options); ToolRunner.printGenericCommandUsage(System.out); return -1; } String language = null; if (cmdline.hasOption(LANGUAGE_OPTION)) { language = cmdline.getOptionValue(LANGUAGE_OPTION); if (language.length() != 2) { System.err.println("Error: \"" + language + "\" unknown language!"); return -1; } } String inputPath = cmdline.getOptionValue(INPUT_OPTION); String outputFile = cmdline.getOptionValue(OUTPUT_FILE_OPTION); boolean keepAll = cmdline.hasOption(KEEP_ALL_OPTION); String tmpPath = "tmp-" + WikipediaDocnoMappingBuilder.class.getSimpleName() + "-" + RANDOM.nextInt(10000); LOG.info("Tool name: " + this.getClass().getName()); LOG.info(" - input: " + inputPath); LOG.info(" - output file: " + outputFile); LOG.info(" - keep all pages: " + keepAll); LOG.info(" - language: " + language); Job job = Job.getInstance(getConf()); job.setJarByClass(WikipediaDocnoMappingBuilder.class); job.setJobName(String.format("BuildWikipediaDocnoMapping[%s: %s, %s: %s, %s: %s]", INPUT_OPTION, inputPath, OUTPUT_FILE_OPTION, outputFile, LANGUAGE_OPTION, language)); job.getConfiguration().setBoolean(KEEP_ALL_OPTION, keepAll); if (language != null) { job.getConfiguration().set("wiki.language", language); } job.setNumReduceTasks(1); FileInputFormat.setInputPaths(job, new Path(inputPath)); FileOutputFormat.setOutputPath(job, new Path(tmpPath)); FileOutputFormat.setCompressOutput(job, false); job.setOutputKeyClass(IntWritable.class); job.setOutputValueClass(IntWritable.class); job.setInputFormatClass(WikipediaPageInputFormat.class); job.setOutputFormatClass(TextOutputFormat.class); job.setMapperClass(MyMapper.class); job.setReducerClass(MyReducer.class); // Delete the output directory if it exists already. FileSystem.get(getConf()).delete(new Path(tmpPath), true); job.waitForCompletion(true); long cnt = keepAll ? job.getCounters().findCounter(PageTypes.TOTAL).getValue() : job.getCounters().findCounter(PageTypes.ARTICLE).getValue(); WikipediaDocnoMapping.writeDocnoMappingData(FileSystem.get(getConf()), tmpPath + "/part-r-00000", (int) cnt, outputFile); FileSystem.get(getConf()).delete(new Path(tmpPath), true); return 0; }
From source file:edu.umd.cloud9.example.bigram.BigramRelativeFrequency.java
/** * Runs this tool.//from w ww . j av a 2s. 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("number of reducers") .create(NUM_REDUCERS)); 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)) { 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 reduceTasks = cmdline.hasOption(NUM_REDUCERS) ? Integer.parseInt(cmdline.getOptionValue(NUM_REDUCERS)) : 1; LOG.info("Tool name: " + BigramRelativeFrequency.class.getSimpleName()); LOG.info(" - input path: " + inputPath); LOG.info(" - output path: " + outputPath); LOG.info(" - num reducers: " + reduceTasks); Job job = Job.getInstance(getConf()); job.setJobName(BigramRelativeFrequency.class.getSimpleName()); job.setJarByClass(BigramRelativeFrequency.class); job.setNumReduceTasks(reduceTasks); FileInputFormat.setInputPaths(job, new Path(inputPath)); FileOutputFormat.setOutputPath(job, new Path(outputPath)); job.setMapOutputKeyClass(PairOfStrings.class); job.setMapOutputValueClass(FloatWritable.class); job.setOutputKeyClass(PairOfStrings.class); job.setOutputValueClass(FloatWritable.class); job.setOutputFormatClass(SequenceFileOutputFormat.class); job.setMapperClass(MyMapper.class); job.setCombinerClass(MyCombiner.class); job.setReducerClass(MyReducer.class); job.setPartitionerClass(MyPartitioner.class); // Delete the output directory if it exists already. Path outputDir = new Path(outputPath); FileSystem.get(getConf()).delete(outputDir, true); long startTime = System.currentTimeMillis(); job.waitForCompletion(true); System.out.println("Job Finished in " + (System.currentTimeMillis() - startTime) / 1000.0 + " seconds"); return 0; }
From source file:esg.node.security.shell.cmds.ESGFusermod.java
public void doInitOptions() { getOptions().addOption("n", "no-prompt", false, "do not ask for confirmation"); Option firstname = OptionBuilder.withArgName("firstname").hasArg(true).withDescription("First name of user") .withLongOpt("firstname").create("fn"); getOptions().addOption(firstname);//from ww w .ja va 2s .co m Option middlename = OptionBuilder.withArgName("middlename").hasArg(true) .withDescription("Middle name of user").withLongOpt("middlename").create("mn"); getOptions().addOption(middlename); Option lastname = OptionBuilder.withArgName("lastname").hasArg(true).withDescription("Last name of user") .withLongOpt("lastname").create("ln"); getOptions().addOption(lastname); Option email = OptionBuilder.withArgName("email").hasArg(true).withDescription("Email address of user") .withLongOpt("email").create("e"); getOptions().addOption(email); Option organization = OptionBuilder.withArgName("organization").hasArg(true) .withDescription("Organization name of user").withLongOpt("organization").create("o"); getOptions().addOption(organization); Option city = OptionBuilder.withArgName("city").hasArg(true).withDescription("City of user") .withLongOpt("city").create("c"); getOptions().addOption(city); Option state = OptionBuilder.withArgName("state").hasArgs().withDescription("State of user") .withLongOpt("state").create("st"); getOptions().addOption(state); Option country = OptionBuilder.withArgName("country").hasArg(true).withDescription("First name of user") .withLongOpt("country").create("cn"); getOptions().addOption(country); Option openid = OptionBuilder.withArgName("openid").hasArg(true).withDescription("OpenID of user") .withLongOpt("openid").create("oid"); getOptions().addOption(openid); }
From source file:esg.node.security.shell.cmds.ESGFuseradd.java
public void doInitOptions() { getOptions().addOption("n", "no-prompt", false, "do not ask for confirmation"); Option firstname = OptionBuilder.withArgName("firstname").hasArg(true).withDescription("First name of user") .withLongOpt("firstname").isRequired(true).create("fn"); getOptions().addOption(firstname);//from www. ja v a 2 s. c om Option middlename = OptionBuilder.withArgName("middlename").hasArg(true) .withDescription("Middle name of user").withLongOpt("middlename").create("mn"); getOptions().addOption(middlename); Option lastname = OptionBuilder.withArgName("lastname").hasArg(true).withDescription("Last name of user") .withLongOpt("lastname").isRequired(true).create("ln"); getOptions().addOption(lastname); Option email = OptionBuilder.withArgName("email").hasArg(true).withDescription("Email address of user") .withLongOpt("email").isRequired(true).create("e"); getOptions().addOption(email); Option organization = OptionBuilder.withArgName("organization").hasArg(true) .withDescription("Organization name of user").withLongOpt("organization").create("o"); getOptions().addOption(organization); Option city = OptionBuilder.withArgName("city").hasArg(true).withDescription("City of user") .withLongOpt("city").create("c"); getOptions().addOption(city); Option state = OptionBuilder.withArgName("state").hasArgs().withDescription("State of user") .withLongOpt("state").create("st"); getOptions().addOption(state); Option country = OptionBuilder.withArgName("country").hasArg(true).withDescription("First name of user") .withLongOpt("country").create("cn"); getOptions().addOption(country); Option openid = OptionBuilder.withArgName("openid").hasArg(true).withDescription("OpenID of user") .withLongOpt("openid").create("oid"); getOptions().addOption(openid); }
From source file:esg.node.security.shell.cmds.ESGFpasswd.java
public void doInitOptions() { getOptions().addOption("i", "prompt", false, "request confirmation before performing action"); getOptions().addOption("d", "disable", false, "disable this account"); getOptions().addOption("c", "check", false, "Allows users to check if thier password is valid"); Option user = OptionBuilder.withArgName("user").hasArg(true) .withDescription("User for which you wish to change password").withLongOpt("user").create("u"); getOptions().addOption(user);//from w w w .ja va 2s. c o m }
From source file:edu.umd.honghongie.ExtractTopPersonalizedPageRankNodes.java
/** * Runs this tool./* w w w .j a va 2 s. c o 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)); //****** options.addOption( OptionBuilder.withArgName("node").hasArg().withDescription("source nodes").create(SOURCE)); 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) || !cmdline.hasOption(SOURCE)) //source node { 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 = "TestOutput"; //*********???? int n = Integer.parseInt(cmdline.getOptionValue(TOP)); //******* String nodeid = cmdline.getOptionValue(SOURCE); ArrayListOfInts sourceids = new ArrayListOfInts(); String ss[] = nodeid.split(","); for (int i = 0; i < ss.length; i++) { sourceids.add(Integer.parseInt(ss[i])); } LOG.info("Tool name: " + ExtractTopPersonalizedPageRankNodes.class.getSimpleName()); LOG.info(" - input: " + inputPath); LOG.info(" - output: " + outputPath); LOG.info(" - top: " + n); LOG.info(" - source node: " + nodeid); for (int i = 0; i < sourceids.size(); i++) { int source = sourceids.get(i); iterateSort(i, source, n, inputPath, outputPath); //times, sourcenode, top n } return 0; }
From source file:esg.node.security.shell.cmds.ESGFassociate.java
public void doInitOptions() { getOptions().addOption("n", "no_prompt", false, "suppress request confirmation before making associations"); Option username = OptionBuilder.withArgName("username").hasArg(true) .withDescription("user name you wish to associate").withLongOpt("username").isRequired(true) .create("u"); getOptions().addOption(username);//w w w. ja v a 2 s . c o m Option groupname = OptionBuilder.withArgName("groupname").hasArg(true) .withDescription("group name you wish to associate").withLongOpt("groupname").isRequired(false) .create("g"); getOptions().addOption(groupname); Option rolename = OptionBuilder.withArgName("rolename").hasArg(true) .withDescription("role name you wish to associate").withLongOpt("rolename").isRequired(false) .create("r"); getOptions().addOption(rolename); Option add = new Option("add", false, "creates a permission entry from the given (user,group,role) tuple"); Option remove = new Option("remove", false, "removes the specified group and role from specified user"); Option removeGroupFromUser = new Option("remove_group_from_user", false, "removes the specified group from specified user"); Option removeRoleFromUser = new Option("remove_role_from_user", false, "removes the specified role from specified user"); Option removeAll = new Option("remove_all", false, "removes all group and roles associated with user"); OptionGroup directiveOptionGroup = new OptionGroup(); directiveOptionGroup.addOption(add); directiveOptionGroup.addOption(remove); directiveOptionGroup.addOption(removeGroupFromUser); directiveOptionGroup.addOption(removeRoleFromUser); directiveOptionGroup.addOption(removeAll); getOptions().addOptionGroup(directiveOptionGroup); }
From source file:fr.ens.biologie.genomique.eoulsan.actions.ExecJarHadoopAction.java
/** * Create options for command line//from ww w.j av a 2 s.com * @return an Options object */ @SuppressWarnings("static-access") private static Options makeOptions() { // create Options object final Options options = new Options(); // Help option options.addOption("h", "help", false, "display this help"); // Description option options.addOption(OptionBuilder.withArgName("description").hasArg().withDescription("job description") .withLongOpt("jobdesc").create('d')); // Environment option options.addOption(OptionBuilder.withArgName("environment").hasArg() .withDescription("environment description").withLongOpt("envdesc").create('e')); // UploadOnly option options.addOption("upload", false, "upload only"); // Parent job creation time options.addOption(OptionBuilder.withArgName("parent-job-time").hasArg().withDescription("parent job time") .withLongOpt("parent-job").create('p')); return options; }