/** * Tells if the option can accept more arguments. * * @return false if the maximum number of arguments is reached * @since 1.3 */ boolean acceptsArg() { return (hasArg() || hasArgs() || hasOptionalArg()) && (numberOfArgs <= 0 || values.size() < numberOfArgs); }
else if (!o.hasArgs()) { args.add(argument); args.add(v);
@Test public void testHasArgs() { Option option = new Option("f", null); option.setArgs(0); assertFalse(option.hasArgs()); option.setArgs(1); assertFalse(option.hasArgs()); option.setArgs(10); assertTrue(option.hasArgs()); option.setArgs(Option.UNLIMITED_VALUES); assertTrue(option.hasArgs()); option.setArgs(Option.UNINITIALIZED); assertFalse(option.hasArgs()); }
@Test public void testCompleteOption( ) { Option simple = OptionBuilder.withLongOpt( "simple option") .hasArg( ) .isRequired( ) .hasArgs( ) .withType( Float.class ) .withDescription( "this is a simple option" ) .create( 's' ); assertEquals( "s", simple.getOpt() ); assertEquals( "simple option", simple.getLongOpt() ); assertEquals( "this is a simple option", simple.getDescription() ); assertEquals( simple.getType(), Float.class ); assertTrue( simple.hasArg() ); assertTrue( simple.isRequired() ); assertTrue( simple.hasArgs() ); }
@Test public void testTwoCompleteOptions( ) { Option simple = OptionBuilder.withLongOpt( "simple option") .hasArg( ) .isRequired( ) .hasArgs( ) .withType( Float.class ) .withDescription( "this is a simple option" ) .create( 's' ); assertEquals( "s", simple.getOpt() ); assertEquals( "simple option", simple.getLongOpt() ); assertEquals( "this is a simple option", simple.getDescription() ); assertEquals( simple.getType(), Float.class ); assertTrue( simple.hasArg() ); assertTrue( simple.isRequired() ); assertTrue( simple.hasArgs() ); simple = OptionBuilder.withLongOpt( "dimple option") .hasArg( ) .withDescription( "this is a dimple option" ) .create( 'd' ); assertEquals( "d", simple.getOpt() ); assertEquals( "dimple option", simple.getLongOpt() ); assertEquals( "this is a dimple option", simple.getDescription() ); assertEquals( String.class, simple.getType() ); assertTrue( simple.hasArg() ); assertTrue( !simple.isRequired() ); assertTrue( !simple.hasArgs() ); }
/** * Tells if the option can accept more arguments. * * @return false if the maximum number of arguments is reached * @since 1.3 */ boolean acceptsArg() { return (hasArg() || hasArgs() || hasOptionalArg()) && (numberOfArgs <= 0 || values.size() < numberOfArgs); }
/** * Dump state, suitable for debugging. * * @return Stringified form of this object */ public String toString() { StringBuffer buf = new StringBuffer().append("[ option: "); buf.append(opt); if (longOpt != null) { buf.append(" ").append(longOpt); } buf.append(" "); if (hasArgs()) { buf.append("[ARG...]"); } else if (hasArg()) { buf.append(" [ARG]"); } buf.append(" :: ").append(description); if (type != null) { buf.append(" :: ").append(type); } buf.append(" ]"); return buf.toString(); }
/** * Dump state, suitable for debugging. * * @return Stringified form of this object */ public String toString() { StringBuffer buf = new StringBuffer().append("[ option: "); buf.append(opt); if (longOpt != null) { buf.append(" ").append(longOpt); } buf.append(" "); if (hasArgs()) { buf.append("[ARG...]"); } else if (hasArg()) { buf.append(" [ARG]"); } buf.append(" :: ").append(description); if (type != null) { buf.append(" :: ").append(type); } buf.append(" ]"); return buf.toString(); }
/** * <p>If there is a current option and it can have an argument * value then add the token to the processed tokens list and * set the current option to null.</p> * <p>If there is a current option and it can have argument * values then add the token to the processed tokens list.</p> * <p>If there is not a current option add the special token * "<b>--</b>" and the current <code>value</code> to the processed * tokens list. The add all the remaining <code>argument</code> * values to the processed tokens list.</p> * * @param value The current token */ private void process(String value) { if ((currentOption != null) && currentOption.hasArg()) { if (currentOption.hasArg()) { tokens.add(value); currentOption = null; } else if (currentOption.hasArgs()) { tokens.add(value); } } else { eatTheRest = true; tokens.add("--"); tokens.add(value); } }
/** * Return Mame only args */ public String[] getMameRawArgs () { List<String> mra = new ArrayList<>(); optionsLoop: for (Option o: this.commandLine.getOptions()) { // Discard ia-rcade options for (Option ia: this.iaRcadeOptions.getOptions()) { if (o.getOpt().equals(ia.getOpt())) { continue optionsLoop; } } mra.add('-' + o.getOpt()); if (o.hasArg() || o.hasArgs()) { for (String a: this.commandLine.getOptionValues(o.getOpt())) { mra.add(a); } } } // Add non option args for (String arg: this.commandLine.getArgs()) { mra.add(arg); } return mra.toArray(new String[mra.size()]); }
/** * <p>If there is a current option and it can have an argument * value then add the token to the processed tokens list and * set the current option to null.</p> * <p>If there is a current option and it can have argument * values then add the token to the processed tokens list.</p> * <p>If there is not a current option add the special token * "<b>--</b>" and the current <code>value</code> to the processed * tokens list. The add all the remaining <code>argument</code> * values to the processed tokens list.</p> * * @param value The current token */ private void process(String value) { if ((currentOption != null) && currentOption.hasArg()) { if (currentOption.hasArg()) { tokens.add(value); currentOption = null; } else if (currentOption.hasArgs()) { tokens.add(value); } } else { eatTheRest = true; tokens.add("--"); tokens.add(value); } }
String parse(Option option, UnaryOperator<String> parser) { if (option.hasArgs()) { return option.getValuesList() .stream() .map(u -> parse(option.getLongOpt(), u, parser)) .collect(Collectors.joining(" ")); } if (option.hasArg()) { return parse(option.getLongOpt(), option.getValue(), parser); } return Boolean.TRUE.toString(); }
if (o.hasArg() || o.hasArgs()) { for (String a: this.commandLine.getOptionValues(o.getOpt())) { roa.add(a);
String property = commandLineOptions.property(option).name(); if (option.hasArgs()) {
public MavenOptionCompleter() { mavenOptions().forEach(option -> { if (option.hasArg() || option.hasArgs() || option.hasOptionalArg()) { // TODO: adjust for options with arguments; for now omit } else { delegate.add("-" + option.getOpt()); delegate.add("--" + option.getLongOpt()); } }); }
String key = String.format("backend.%s.%s", b.getIdentifier(), option.getLongOpt() != null ? option.getLongOpt() : option.getOpt()); if(option.hasArg()) { if(option.hasArgs()) { result.setProperty(key, Arrays.asList(cmd.getOptionValues(option.getOpt()))); } else {
protected static void dumpParams(CommandLine cl, Options options) { List<String> deferred = new ArrayList<>(); LOGGER.info("Options:"); for (Option option : options.getOptions()) { String name = (option.getOpt() != null) ? option.getOpt() : option.getLongOpt(); if (cl.hasOption(name)) { if (option.hasArgs()) { LOGGER.info("Option " + name + " = " + Arrays.toString(cl.getOptionValues(name))); } else if (option.hasArg()) { LOGGER.info("Option " + name + " = " + cl.getOptionValue(name)); } else { LOGGER.info("Option " + name); } } else { deferred.add(name); } } LOGGER.debug("---"); for (String name : deferred) { LOGGER.debug("Option " + name + " not set"); } }