public BeelineOptionsProcessor() { options.addOption(OptionBuilder.hasArg().withArgName("url").create('u')); options.addOption(OptionBuilder.hasArg().withArgName("username").create('n')); options.addOption(OptionBuilder.hasArg().withArgName("password").create('p')); }
private boolean parseCommandLineOpts(String[] args) throws ParseException { Options options = new Options(); options.addOption("l", "dataDirs", true, "Comma-separated list of data " + "directories which the tool must verify. This option is mandatory") .addOption("h", "help", false, "Display help") .addOption("e", "eventValidator", true, "Fully Qualified Name of Event Validator Implementation"); Option property = OptionBuilder.withArgName("property=value") .hasArgs(2) .withValueSeparator() .withDescription("custom properties") .create("D"); options.addOption(property); CommandLineParser parser = new GnuParser(); CommandLine commandLine = parser.parse(options, args); if (commandLine.hasOption("help")) { new HelpFormatter().printHelp("bin/flume-ng tool fcintegritytool ", options, true); return false;
options.addOption(OptionBuilder .withValueSeparator() .hasArgs(2) .withArgName("property=value") .withLongOpt("hiveconf") .withDescription("Use value for given property") .create()); options.addOption(OptionBuilder .hasArgs(1) .withArgName("versionNumber") .withLongOpt("deregister") .withDescription("Deregister all instances of given version from dynamic service discovery") .create()); options.addOption(OptionBuilder .hasArgs(0) .withLongOpt("listHAPeers") .withDescription("List all HS2 instances when running in Active Passive HA mode") .create()); options.addOption(OptionBuilder .hasArgs(1) .withArgName("workerIdentity") .withLongOpt("failover") .withDescription("Manually failover Active HS2 instance to passive standby mode") .create()); options.addOption(new Option("H", "help", false, "Print help information"));
private static Option option(int argCount, String shortName, String longName, String argName, String description) { Option option = OptionBuilder.hasArgs(argCount) .withArgName(argName) .withLongOpt(longName) .withDescription(description) .create(shortName); return option; }
private static Options buildGeneralOptions(Options opts) { Options r = new Options(); for (Object o : opts.getOptions()) r.addOption((Option) o); Option jar = OptionBuilder.withArgName("path").hasArg() .withDescription("topology jar of the submitted topology").create("jar"); r.addOption(jar); Option conf = OptionBuilder.withArgName("configuration file").hasArg() .withDescription("an application configuration file").create("conf"); r.addOption(conf); return r; }
public CryptoProcessor(HadoopShims.HdfsEncryptionShim encryptionShim, HiveConf conf) { this.encryptionShim = encryptionShim; this.conf = conf; CREATE_KEY_OPTIONS = new Options(); CREATE_KEY_OPTIONS.addOption(OptionBuilder.hasArg().withLongOpt("keyName").isRequired().create()); CREATE_KEY_OPTIONS.addOption(OptionBuilder.hasArg().withLongOpt("bitLength").create()); // optional DELETE_KEY_OPTIONS = new Options(); DELETE_KEY_OPTIONS.addOption(OptionBuilder.hasArg().withLongOpt("keyName").isRequired().create()); CREATE_ZONE_OPTIONS = new Options(); CREATE_ZONE_OPTIONS.addOption(OptionBuilder.hasArg().withLongOpt("keyName").isRequired().create()); CREATE_ZONE_OPTIONS.addOption(OptionBuilder.hasArg().withLongOpt("path").isRequired().create()); }
@Override @SuppressWarnings( "static-access" ) public int run( String[] args ) throws Exception { Options options = new Options(); options.addOption( OptionBuilder.withArgName( "path" ).hasArg().withDescription( "output" ).create( OUTPUT_OPTION ) ); options.addOption( OptionBuilder.withArgName( "path" ).hasArg().withDescription( "multi-output" ).create( MULTI_OUTPUT_OPTION ) ); options.addOption( OptionBuilder.withArgName( "path" ).hasArg().withDescription( "output for anchor map" ).create( ANCHORMAP_OPTION ) ); options.addOption( OptionBuilder.withArgName( "path" ).hasArg().withDescription( "output for anchor cf map" ).create( CFMAP_OPTION ) ); options.addOption( OptionBuilder.withArgName( "ngram" ).hasArg().withDescription( "chunk into ngram" ).create( NGRAM_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( OUTPUT_OPTION ) || !cmdline.hasOption( ANCHORMAP_OPTION ) || !cmdline.hasOption( CFMAP_OPTION ) ) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp( this.getClass().getName(), options ); ToolRunner.printGenericCommandUsage( System.out ); return -1; } merge( cmdline.getOptionValue( ANCHORMAP_OPTION ), cmdline.getOptionValue( CFMAP_OPTION ), cmdline.getOptionValue( MULTI_OUTPUT_OPTION ), cmdline.getOptionValue( OUTPUT_OPTION ), cmdline.getOptionValue( NGRAM_OPTION ) ); return 0; }
Option helpopt = OptionBuilder.hasArg(false) .withDescription("print this message") .create("help"); Option inopt = OptionBuilder.hasArg() .isRequired() .withDescription("comma-separated input paths") .create("in"); Option outopt = OptionBuilder.hasArg() .isRequired() .withDescription("The output path.") .create("out"); Option pargs = OptionBuilder.hasArg() .withDescription("A string containing the command line arguments to pass to the tethered process. String should be enclosed in quotes") .create("exec_args"); Option popt = OptionBuilder.hasArg() .isRequired() .withDescription("executable program, usually in HDFS") .create("program"); Option outscopt = OptionBuilder.withType(File.class).hasArg() .isRequired() .withDescription("schema file for output of reducer") .create("outschema"); Option outscmapopt = OptionBuilder.withType(File.class).hasArg()
@Test public void testShortWithoutEqual() throws Exception { String[] args = new String[] { "-fbar" }; Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("foo").hasArg().create('f')); CommandLine cl = parser.parse(options, args); assertEquals("bar", cl.getOptionValue("foo")); }
@Test public void testUnambiguousPartialLongOption2() throws Exception { String[] args = new String[] { "-ver" }; Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("version").create()); options.addOption(OptionBuilder.withLongOpt("help").create()); CommandLine cl = parser.parse(options, args); assertTrue("Confirm --version is set", cl.hasOption("version")); }
private static CommandLine parseArgs(String[] args) throws ParseException { Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("file") .withDescription("sequence file to read") .hasArg() .withArgName("<sequence_file_name>") .withType(String.class) .create("f")); options.addOption("o", "print_offsets_only", false, "whether to print only offsets " + "ignoring the message payload"); CommandLineParser parser = new GnuParser(); return parser.parse(options, args); }
@Test public void testLs() throws Exception { // create the command line parser CommandLineParser parser = new PosixParser(); Options options = new Options(); options.addOption( "a", "all", false, "do not hide entries starting with ." ); options.addOption( "A", "almost-all", false, "do not list implied . and .." ); options.addOption( "b", "escape", false, "print octal escapes for nongraphic characters" ); options.addOption( OptionBuilder.withLongOpt( "block-size" ) .withDescription( "use SIZE-byte blocks" ) .hasArg() .withArgName("SIZE") .create() ); options.addOption( "B", "ignore-backups", false, "do not list implied entried ending with ~"); options.addOption( "c", false, "with -lt: sort by, and show, ctime (time of last modification of file status information) with -l:show ctime and sort by name otherwise: sort by ctime" ); options.addOption( "C", false, "list entries by columns" ); String[] args = new String[]{ "--block-size=10" }; CommandLine line = parser.parse( options, args ); assertTrue( line.hasOption( "block-size" ) ); assertEquals( line.getOptionValue( "block-size" ), "10" ); }
@Test public void testWithRequiredOption() throws Exception { String[] args = new String[] { "-b", "file" }; Options options = new Options(); options.addOption("a", "enable-a", false, null); options.addOption(OptionBuilder.withLongOpt("bfile").hasArg().isRequired().create('b')); CommandLine cl = parser.parse(options,args); assertTrue("Confirm -a is NOT set", !cl.hasOption("a")); assertTrue("Confirm -b is set", cl.hasOption("b")); assertTrue("Confirm arg of -b", cl.getOptionValue("b").equals("file")); assertTrue("Confirm NO of extra args", cl.getArgList().size() == 0); }
Option timeLimit = OptionBuilder.withLongOpt("limit").hasArg() .withValueSeparator() .withDescription("Set time limit for execution, in minutes") .create("l"); Option age = OptionBuilder.withLongOpt("age").hasArg() .withValueSeparator() .withDescription("Age (in days) of cache item before being recomputed") .create("a"); Option server = OptionBuilder.withLongOpt("server").hasArg() .withValueSeparator() .withDescription("The NLT server address") .create("s"); Option numResults = OptionBuilder.withLongOpt("results").hasArg() .withValueSeparator() .withDescription("Number of results per item") .create("r"); Option configFile = OptionBuilder.withLongOpt("file").hasArg() .withValueSeparator() .withDescription("Use the specified configuration file") .create(); };
options.addOption(OptionBuilder .hasArg() .withArgName("abort-pct") .withDescription("Percentage of transactions to abort, defaults to 5") .withLongOpt("abortpct") .create('a')); options.addOption(OptionBuilder .hasArgs() .withArgName("column-names") .withDescription("column names of table to write to") .withLongOpt("columns") .withValueSeparator(',') .isRequired() .create('c')); .hasArg() .withArgName("database") .withDescription("Database of table to write to") .withLongOpt("database") .isRequired() .create('d')); .hasArg() .withArgName("frequency") .withDescription("How often to commit a transaction, in seconds, defaults to 1") .withLongOpt("frequency") .create('f'));
options.addOption(OptionBuilder .hasArg() .withArgName("exec") .withDescription("hcat command given from command line") .create('e')); options.addOption(OptionBuilder .hasArg() .withArgName("file") .withDescription("hcat commands in file") .create('f')); .hasArg(). withArgName("group"). withDescription("group for the db/table specified in CREATE statement"). create('g')); .hasArg() .withArgName("perms") .withDescription("permissions for the db/table specified in CREATE statement") .create('p')); .hasArgs(2) .withArgName("property=value") .withValueSeparator() .withDescription("use hadoop value for given property") .create('D'));
@Test public void testUnambiguousPartialLongOption3() throws Exception { String[] args = new String[] { "--ver=1" }; Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("verbose").hasOptionalArg().create()); options.addOption(OptionBuilder.withLongOpt("help").create()); CommandLine cl = parser.parse(options, args); assertTrue("Confirm --verbose is set", cl.hasOption("verbose")); assertEquals("1", cl.getOptionValue("verbose")); }
public void testAnt() throws Exception { options.addOption( "listener", true, "add an instance of a class as a project listener" ); options.addOption( "buildfile", true, "use given buildfile" ); options.addOption( OptionBuilder.withDescription( "use value for given property" ) .hasArgs() .withValueSeparator() .create( 'D' ) ); options.addOption( "find", true, "search for buildfile towards the root of the filesystem and use it" ); "-projecthelp" }; CommandLine line = parser.parse( options, args ); String[] opts = line.getOptionValues( "D" ); assertEquals( "property", opts[0] ); assertEquals( "value", opts[1] ); assertEquals( line.getOptionValue( "buildfile"), "mybuild.xml" ); assertTrue( line.hasOption( "projecthelp") );
@Test public void testPropertyOptionRequired() throws Exception { Options opts = new Options(); opts.addOption(OptionBuilder.isRequired().create("f")); Properties properties = new Properties(); properties.setProperty("f", "true"); CommandLine cmd = parse(parser, opts, null, properties); assertTrue(cmd.hasOption("f")); }
@SuppressWarnings("static-access") public boolean parse(String[] args, boolean defaultVal) throws ParseException { Preconditions.checkState(parsed == false, "Craete a new instance for different option sets"); parsed = true; Options opts = new Options(); Option opt = OptionBuilder .withArgName("splits_in_client") .hasArg() .withDescription( "specify whether splits should be generated in the client") .create("generateSplitsInClient"); opts.addOption(opt); CommandLineParser parser = new GnuParser(); cmdLine = parser.parse(opts, args, false); if (cmdLine.hasOption("generateSplitsInClient")) { defaultVal = Boolean.parseBoolean(cmdLine .getOptionValue("generateSplitsInClient")); } otherArgs = cmdLine.getArgs(); return defaultVal; }