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; }
@Test public void test14786() throws Exception { Option o = OptionBuilder.isRequired().withDescription("test").create("test"); Options opts = new Options(); opts.addOption(o); opts.addOption(o); CommandLineParser parser = new GnuParser(); String[] args = new String[] { "-test" }; CommandLine line = parser.parse( opts, args ); assertTrue( line.hasOption( "test" ) ); }
@Test public void testSpecialOptChars() throws Exception { // '?' Option opt1 = OptionBuilder.withDescription("help options").create('?'); assertEquals("?", opt1.getOpt()); // '@' Option opt2 = OptionBuilder.withDescription("read from stdin").create('@'); assertEquals("@", opt2.getOpt()); // ' ' try { OptionBuilder.create(' '); fail( "IllegalArgumentException not caught" ); } catch (IllegalArgumentException e) { // success } }
@Test public void testOptionArgNumbers() { Option opt = OptionBuilder.withDescription( "option description" ) .hasArgs( 2 ) .create( 'o' ); assertEquals( 2, opt.getArgs() ); }
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; }
@Test public void testBuilderIsResettedAlways() { try { OptionBuilder.withDescription("JUnit").create('"'); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException e) { // expected } assertNull("we inherited a description", OptionBuilder.create('x').getDescription()); try { OptionBuilder.withDescription("JUnit").create(); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException e) { // expected } assertNull("we inherited a description", OptionBuilder.create('x').getDescription()); } }
private static Options buildGeneralOptions(Options opts) { Options r = new Options(); for (Object o : opts.getOptions()) r.addOption((Option) o); Option workerNum = OptionBuilder.withArgName("worker num per batch").hasArg() .withDescription("number of workers to upgrade").create("n"); r.addOption(workerNum); Option comp = OptionBuilder.withArgName("component to upgrade").hasArg() .withDescription("component id to upgrade, note that only one component is allowed at a time") .create("p"); r.addOption(comp); Option workers = OptionBuilder.withArgName("workers to upgrade").hasArg() .withDescription("workers to upgrade, in the format: host1:port1,host2:port2,...").create("w"); r.addOption(workers); return r; }
@Test public void testBaseOptionStringOpt() { Option base = OptionBuilder.withDescription( "option description") .create( "o" ); assertEquals( "o", base.getOpt() ); assertEquals( "option description", base.getDescription() ); assertTrue( !base.hasArg() ); }
@SuppressWarnings("static-access") HiveMetastoreCli(Configuration configuration) { super("hivemetastore", true); this.port = MetastoreConf.getIntVar(configuration, ConfVars.SERVER_PORT); // -p port OPTIONS.addOption(OptionBuilder .hasArg() .withArgName("port") .withDescription("Hive Metastore port number, default:" + this.port) .create('p')); }
@Test public void testIllegalOptions() { // bad single character option try { OptionBuilder.withDescription( "option description" ).create( '"' ); fail( "IllegalArgumentException not caught" ); } catch( IllegalArgumentException exp ) { // success } // bad character in option string try { OptionBuilder.create( "opt`" ); fail( "IllegalArgumentException not caught" ); } catch( IllegalArgumentException exp ) { // success } // valid option try { OptionBuilder.create( "opt" ); // success } catch( IllegalArgumentException exp ) { fail( "IllegalArgumentException caught" ); } }
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 testBaseOptionCharOpt() { Option base = OptionBuilder.withDescription( "option description") .create( 'o' ); assertEquals( "o", base.getOpt() ); assertEquals( "option description", base.getDescription() ); assertTrue( !base.hasArg() ); }
static Options createOptions() { Options result = new Options(); result.addOption(OptionBuilder .withLongOpt("check-only") .withDescription("Check acid orc file for valid acid key index and exit without fixing") .create('c')); result.addOption(OptionBuilder .withLongOpt("recover") .withDescription("Fix the acid key index for acid orc file if it requires fixing") .create('r')); result.addOption(OptionBuilder .withLongOpt("backup-path") .withDescription("specify a backup path to store the corrupted files (default: /tmp)") .hasArg() .create()); result.addOption(OptionBuilder .withLongOpt("help") .withDescription("print help message") .create('h')); return result; }
static Options buildGeneralOptions(Options opts) { Options r = new Options(); for (Object o : opts.getOptions()) r.addOption((Option) o); Option libjars = OptionBuilder.withArgName("paths").hasArg().withDescription("comma separated jars to be used by the submitted topology").create("libjars"); r.addOption(libjars); optionProcessors.put("libjars", new LibjarsProcessor()); Option conf = OptionBuilder.withArgName("configuration file").hasArg().withDescription("an application configuration file").create("conf"); r.addOption(conf); optionProcessors.put("conf", new ConfFileProcessor()); // Must come after `conf': this option is of higher priority Option extraConfig = OptionBuilder.withArgName("D").hasArg().withDescription("extra configurations (preserving types)").create("D"); r.addOption(extraConfig); optionProcessors.put("D", new ExtraConfigProcessor()); return r; }
static Options createOptions() { Options result = new Options(); // add -r and --dry-run to generate list only result.addOption(OptionBuilder .withLongOpt("dry-run") .withDescription("Generate a list of dangling scratch dir, printed on console") .create('r')); // add -s and --scratchdir to specify a non-default scratch dir result.addOption(OptionBuilder .withLongOpt("scratchdir") .withDescription("Specify a non-default location of the scratch dir") .hasArg() .create('s')); // add -v and --verbose to print verbose message result.addOption(OptionBuilder .withLongOpt("verbose") .withDescription("Print verbose message") .create('v')); result.addOption(OptionBuilder .withLongOpt("help") .withDescription("print help message") .create('h')); return result; } }
/** * Create commandLine options * @return */ private static Options initCommandLineOptions(){ Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("gui") .withDescription("Start VectAlign GUI") .create(OPTION_GUI)); options.addOption(OptionBuilder.withLongOpt("start") .withDescription("Starting VectorDrawable path (\"string\", txt file or SVG file)") .hasArg() .withArgName("\"string\"|txt_file|svg_file") .create(OPTION_FROM)); options.addOption(OptionBuilder.withLongOpt("end") .withDescription("Ending VectorDrawable path (\"string\", txt file or SVG file)") .hasArg() .withArgName("\"string\"|txt_file|svg_file") .create(OPTION_TO)); options.addOption(OptionBuilder.withLongOpt("mode") .withDescription("Aligning technique (default is BASE)") .hasArg() .withArgName("BASE|LINEAR|SUB_BASE|SUB_LINEAR") .create(OPTION_MODE)); options.addOption(OptionBuilder.withLongOpt("version") .withDescription("Print the version of the application") .create(OPTION_VERSION)); options.addOption(OptionBuilder.withLongOpt("help").create(OPTION_HELP)); return options; }
/** * Instantiates a new CLI options processor. */ @SuppressWarnings("static-access") public OptionsProcessor() { // -e 'quoted-query-string' options.addOption(OptionBuilder.hasArg() .withArgName("quoted-command-string") .withDescription("Remote command line").create('e')); // -h hostname/ippaddress options.addOption(OptionBuilder.hasArg().withArgName("hostname") .withDescription("connecting to Thrift Server on remote host") .create('h')); // -p port options.addOption(OptionBuilder.hasArg().withArgName("port") .withDescription("connecting to Thrift Server on port number") .create('p')); // -c 'thrift-config' options.addOption(OptionBuilder.hasArg().withArgName("thrift-config") .withDescription("Thrift property file").create('c')); // [-H|--help] options.addOption(new Option("H", "help", false, "Print help information")); }
result.addOption(OptionBuilder .withLongOpt("location") .withDescription("HS2 url") .hasArg() .create('l')); result.addOption(OptionBuilder .withLongOpt("user") .withDescription("user name") .hasArg() .create('u')); result.addOption(OptionBuilder .withLongOpt("pwd") .withDescription("password") .hasArg() .create('p')); .withDescription("number of splits") .withValueSeparator() .hasArgs(2) .withArgName("property=value") .withLongOpt("hiveconf") .withDescription("Use value for given property") .withDescription("help")
synchronized (OptionBuilder.class) { Options options = new Options(); Option oconf = OptionBuilder.withArgName("configuration file") .hasArg() .withDescription("specify an application configuration file") .withLongOpt(ARG_CONF) .create(ARG_CONF_SHORT); Option confclass = OptionBuilder.withArgName("configuration classname") .hasArg() .withDescription( "Classname of a Hadoop Configuration subclass to load") .withLongOpt(ARG_CONFCLASS) .create(ARG_CONFCLASS_SHORT); Option property = OptionBuilder.withArgName("property=value") .hasArg() .withDescription("use value for given property") .create('D'); options.addOption(oconf); options.addOption(property); options.addOption(confclass); return options;
public CliOptionsProcessor() { options.addOption(OptionBuilder.hasArg().withArgName("databasename").withLongOpt("database") .withDescription("Specify the database to use").create()); options.addOption(OptionBuilder.hasArg().withArgName("quoted-query-string").withDescription ("SQL from command line").create('e')); options.addOption(OptionBuilder.hasArg().withArgName("filename").withDescription("SQL from " + "files").create('f')); options.addOption(OptionBuilder.hasArg().withArgName("filename").withDescription ("Initialization SQL file").create('i')); options.addOption(OptionBuilder.withValueSeparator().hasArgs(2).withArgName("property=value") .withLongOpt("hiveconf").withDescription("Use value for given property").create()); options.addOption(OptionBuilder.withValueSeparator().hasArgs(2).withArgName("key=value") .withLongOpt("define").withDescription("Variable substitution to apply to Hive commands. e" + ".g. -d A=B or --define A=B").create('d')); options.addOption(OptionBuilder.withValueSeparator().hasArgs(2).withArgName("key=value") .withLongOpt("hivevar").withDescription("Variable substitution to apply to Hive commands. " + "e.g. --hivevar A=B").create());