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 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")); }
@Test public void testOptionGroupLong() throws Exception { OptionGroup group = new OptionGroup(); group.addOption(OptionBuilder.withLongOpt("foo").create()); group.addOption(OptionBuilder.withLongOpt("bar").create()); Options options = new Options(); options.addOptionGroup(group); CommandLine cl = parser.parse(options, new String[] { "--bar" }); assertTrue(cl.hasOption("bar")); assertEquals("selected option", "bar", group.getSelected()); }
@Test public void testGetOptionProperties() throws Exception { String[] args = new String[] { "-Dparam1=value1", "-Dparam2=value2", "-Dparam3", "-Dparam4=value4", "-D", "--property", "foo=bar" }; Options options = new Options(); options.addOption(OptionBuilder.withValueSeparator().hasOptionalArgs(2).create('D')); options.addOption(OptionBuilder.withValueSeparator().hasArgs(2).withLongOpt("property").create()); Parser parser = new GnuParser(); CommandLine cl = parser.parse(options, args); Properties props = cl.getOptionProperties("D"); assertNotNull("null properties", props); assertEquals("number of properties in " + props, 4, props.size()); assertEquals("property 1", "value1", props.getProperty("param1")); assertEquals("property 2", "value2", props.getProperty("param2")); assertEquals("property 3", "true", props.getProperty("param3")); assertEquals("property 4", "value4", props.getProperty("param4")); assertEquals("property with long format", "bar", cl.getOptionProperties("property").getProperty("foo")); }
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 testUnambiguousPartialLongOption1() 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")); }
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; }
@Test public void test11457() throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("verbose").create()); String[] args = new String[]{"--verbose"}; CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); assertTrue(cmd.hasOption("verbose")); }
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()); }
@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")); }
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; } }
@Test public void testUnambiguousPartialLongOption4() 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 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()); }
@Test public void testAmbiguousLongWithoutEqualSingleDash() throws Exception { String[] args = new String[] { "-b", "-foobar" }; Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("foo").hasOptionalArg().create('f')); options.addOption(OptionBuilder.withLongOpt("bar").hasOptionalArg().create('b')); CommandLine cl = parser.parse(options, args); assertTrue(cl.hasOption("b")); assertTrue(cl.hasOption("f")); assertEquals("bar", cl.getOptionValue("foo")); }
/** * 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; }
@Test public void testGetMatchingOpts() { Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("version").create()); options.addOption(OptionBuilder.withLongOpt("verbose").create()); assertTrue(options.getMatchingOptions("foo").isEmpty()); assertEquals(1, options.getMatchingOptions("version").size()); assertEquals(2, options.getMatchingOptions("ver").size()); } }
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; } }
@Test public void testPropertyOptionSingularValue() throws Exception { Options opts = new Options(); opts.addOption(OptionBuilder.hasOptionalArgs(2).withLongOpt("hide").create()); Properties properties = new Properties(); properties.setProperty( "hide", "seek" ); CommandLine cmd = parse(parser, opts, null, properties); assertTrue( cmd.hasOption("hide") ); assertEquals( "seek", cmd.getOptionValue("hide") ); assertTrue( !cmd.hasOption("fake") ); }
static Options createOptions() { Options result = new Options(); 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')); .withLongOpt("num") .withValueSeparator() .hasArgs(2) .withArgName("property=value") .withLongOpt("hiveconf") .withLongOpt("help")
@Before public void setUp() throws Exception { opts.addOption("a", false, "toggle -a"); opts.addOption("b", true, "set -b"); opts.addOption("c", "c", false, "toggle -c"); opts.addOption("d", "d", true, "set -d"); opts.addOption(OptionBuilder.hasOptionalArg().create('e')); opts.addOption(OptionBuilder.hasOptionalArg().withLongOpt("fish").create()); opts.addOption(OptionBuilder.hasOptionalArgs().withLongOpt("gravy").create()); opts.addOption(OptionBuilder.hasOptionalArgs(2).withLongOpt("hide").create()); opts.addOption(OptionBuilder.hasOptionalArgs(2).create('i')); opts.addOption(OptionBuilder.hasOptionalArgs().create('j')); String[] args = new String[] { "-a", "-b", "foo", "--c", "--d", "bar" }; Parser parser = new PosixParser(); _cl = parser.parse(opts,args); }