@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); }
@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") ); }
@Test public void testPropertyOverrideValues() throws Exception { Options opts = new Options(); opts.addOption(OptionBuilder.hasOptionalArgs(2).create('i')); opts.addOption(OptionBuilder.hasOptionalArgs().create('j')); String[] args = new String[] { "-j", "found", "-i", "ink" }; Properties properties = new Properties(); properties.setProperty( "j", "seek" ); CommandLine cmd = parse(parser, opts, args, properties); assertTrue( cmd.hasOption("j") ); assertEquals( "found", cmd.getOptionValue("j") ); assertTrue( cmd.hasOption("i") ); assertEquals( "ink", cmd.getOptionValue("i") ); assertTrue( !cmd.hasOption("fake") ); }
@Test public void testPropertiesOption2() throws Exception { String[] args = new String[] { "-Dparam1", "-Dparam2=value2", "-D"}; Options options = new Options(); options.addOption(OptionBuilder.withValueSeparator().hasOptionalArgs(2).create('D')); CommandLine cl = parser.parse(options, args); Properties props = cl.getOptionProperties("D"); assertNotNull("null properties", props); assertEquals("number of properties in " + props, 2, props.size()); assertEquals("property 1", "true", props.getProperty("param1")); assertEquals("property 2", "value2", props.getProperty("param2")); List<?> argsleft = cl.getArgList(); assertEquals("Should be no arg left", 0, argsleft.size()); }
@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 Option pkcs11Sign() { return OptionBuilder.withArgName("pkcs11ModulePath pin slot label").hasOptionalArgs(4) .withDescription("sets pkcs11 module path, pin(password), slot index and (optionally) keypair label").create ("pkcs11"); }
UpdateCookieCmd() { super(CMD_UPDATECOOKIE); opts.addOption("b", BOOKIEID, true, "Bookie Id"); opts.addOption("e", EXPANDSTORAGE, false, "Expand Storage"); opts.addOption("l", LIST, false, "List paths of all the cookies present locally and on zookkeeper"); @SuppressWarnings("static-access") Option deleteOption = OptionBuilder.withLongOpt(DELETE).hasOptionalArgs(1) .withDescription("Delete cookie both locally and in ZooKeeper").create("d"); opts.addOption(deleteOption); }
private static Options createOptions() { Options options = new Options(); options.addOption(PROPERTIES_PATH, true, "reporting properties path"); options.addOption(REPORT_PATH, true, "target report path"); options.addOption(OUTPUT_PATH, true, "output document path"); options.addOption(TEMPLATE_CODE, true, "template code"); OptionBuilder .withArgName("parameter=value") .hasOptionalArgs() .withValueSeparator() .withDescription("report parameter"); Option reportParam = OptionBuilder.create(REPORT_PARAMETER); options.addOption(reportParam); return options; } }
private static Options createOptions() { Options options = new Options(); options.addOption(PROPERTIES_PATH, true, "reporting properties path"); options.addOption(REPORT_PATH, true, "target report path"); options.addOption(OUTPUT_PATH, true, "output document path"); options.addOption(TEMPLATE_CODE, true, "template code"); OptionBuilder .withArgName("parameter=value") .hasOptionalArgs() .withValueSeparator() .withDescription("report parameter"); Option reportParam = OptionBuilder.create(REPORT_PARAMETER); options.addOption(reportParam); return options; } }
private static void populateValidOptions() { Option loadKey = OptionBuilder.hasOptionalArgs(1).withArgName("loadKey").withLongOpt("loadKey").withDescription("Load Key").create(); validOptions_.addOption(loadKey); validOptions_.addOption("gt", true, "Records must be greater than this value " + "(binary, double-slash-escaped)"); validOptions_.addOption("lt", true, "Records must be less than this value (binary, double-slash-escaped)"); validOptions_.addOption("gte", true, "Records must be greater than or equal to this value"); validOptions_.addOption("lte", true, "Records must be less than or equal to this value"); validOptions_.addOption("regex", true, "Record must match this regular expression"); validOptions_.addOption("cacheBlocks", true, "Set whether blocks should be cached for the scan"); validOptions_.addOption("caching", true, "Number of rows scanners should cache"); validOptions_.addOption("limit", true, "Per-region limit"); validOptions_.addOption("maxResultsPerColumnFamily", true, "Limit the maximum number of values returned per row per column family"); validOptions_.addOption("delim", true, "Column delimiter"); validOptions_.addOption("ignoreWhitespace", true, "Ignore spaces when parsing columns"); validOptions_.addOption("caster", true, "Caster to use for converting values. A class name, " + "HBaseBinaryConverter, or Utf8StorageConverter. For storage, casters must implement LoadStoreCaster."); Option noWal = OptionBuilder.hasOptionalArgs(1).withArgName("noWAL").withLongOpt("noWAL").withDescription("Sets the write ahead to false for faster loading. To be used with extreme caution since this could result in data loss (see http://hbase.apache.org/book.html#perf.hbase.client.putwal).").create(); validOptions_.addOption(noWal); validOptions_.addOption("minTimestamp", true, "Record must have timestamp greater or equal to this value"); validOptions_.addOption("maxTimestamp", true, "Record must have timestamp less then this value"); validOptions_.addOption("timestamp", true, "Record must have timestamp equal to this value"); validOptions_.addOption("includeTimestamp", false, "Record will include the timestamp after the rowkey on store (rowkey, timestamp, ...)"); validOptions_.addOption("includeTombstone", false, "Record will include a tombstone marker on store after the rowKey and timestamp (if included) (rowkey, [timestamp,] tombstone, ...)"); }
private static void newOption(final Collection<? super Option> options, @Nullable final Character shortName, final String longName, final int argCount, final boolean argOpt, @Nullable final String argName, final String description) { OptionBuilder.withLongOpt(longName); OptionBuilder.withDescription(description); if (argCount != 0) { OptionBuilder.withArgName(argName); if (argOpt) { if (argCount == 1) { OptionBuilder.hasOptionalArg(); } else if (argCount > 1) { OptionBuilder.hasOptionalArgs(argCount); } else { OptionBuilder.hasOptionalArgs(); } } else { if (argCount == 1) { OptionBuilder.hasArg(); } else if (argCount > 1) { OptionBuilder.hasArgs(argCount); } else { OptionBuilder.hasArgs(); } } } options.add(shortName == null ? OptionBuilder.create() : OptionBuilder.create(shortName)); }
.withArgName("RDF/XML|N-TRIPLE|N3|NQUADS").hasOptionalArgs(1) .withDescription("RDF output format (default: RDF/XMl)") .hasArg(true).create("format");
.hasOptionalArgs() .withArgName("REGISTER_INFO_TYPES") .withValueSeparator(',')
fileHelpGroup.addOption(OptionBuilder.hasArgs(1).hasOptionalArgs(20) .withArgName("file or/and folder name[s]") .withDescription("JSON file[s] or/and director(y|ies) with JSON files (max 20)")
.hasOptionalArgs() .withArgName("REGISTER_INFO_TYPES") .withValueSeparator(',')
OptionBuilder.hasOptionalArgs(o.optionalArg());
.hasOptionalArgs(1) .isRequired(false) .withLongOpt(CliArgs.ARGL_LOG_DIR) .hasOptionalArgs(1) .isRequired(false) .withLongOpt(CliArgs.ARGL_STATS_DIR) .hasOptionalArgs(1) .isRequired(false) .withLongOpt(CliArgs.ARGL_JSON_DIR)
.hasOptionalArgs() .withLongOpt("vulnerabilitySearch") .withDescription("Query the vulnerabilities using various optional parameters. More information can " + .hasOptionalArgs() .withLongOpt("submit-defect") .withDescription("Submit a defect to the defect tracker configured for a specific application.")
OptionBuilder.withLongOpt(CommandArgsEnum.LOAD.longname()) .withDescription(CommandArgsEnum.LOAD.description()) .hasOptionalArgs() .withArgName(CommandArgsEnum.LOAD.argname()) .create(CommandArgsEnum.LOAD.shortname().charAt(0))); OptionBuilder.withLongOpt(CommandArgsEnum.TEST.longname()) .withDescription(CommandArgsEnum.TEST.description()) .hasOptionalArgs() .withArgName(CommandArgsEnum.TEST.argname()) .create(CommandArgsEnum.TEST.shortname().charAt(0))); OptionBuilder.withLongOpt(CommandArgsEnum.RUN.longname()) .withDescription(CommandArgsEnum.RUN.description()) .hasOptionalArgs() .withArgName(CommandArgsEnum.RUN.argname()) .create(CommandArgsEnum.RUN.shortname().charAt(0)));
options.addOption(OptionBuilder .withArgName("prune") .hasOptionalArgs(1) .withDescription( "Prune old results (optionally using specified properties file for configuration)")