/** * 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); }
/** * Add the special token "<b>--</b>" and the current <code>value</code> * to the processed tokens list. Then add all the remaining * <code>argument</code> values to the processed tokens list. * * @param value The current token */ private void processNonOptionToken(String value, boolean stopAtNonOption) { if (stopAtNonOption && (currentOption == null || !currentOption.hasArg())) { eatTheRest = true; tokens.add("--"); } tokens.add(value); }
public String getOptionsAsString() { StringBuilder buf = new StringBuilder(); for (Option option : commandLine.getOptions()) { buf.append(" "); buf.append(option.getOpt()); if (option.hasArg()) { buf.append("="); buf.append(option.getValue()); } } return buf.toString(); }
else if (hasArg())
/** * For each method for which the helper created an {@link Option} and for which the input {@link CommandLine} contains * that option, this method will automatically call the method on the input object with the correct * arguments. */ public void applyCommandLineOptions(CommandLine cli, T embeddedGobblin) { try { for (Option option : cli.getOptions()) { if (!this.methodsMap.containsKey(option.getOpt())) { // Option added by cli driver itself. continue; } if (option.hasArg()) { this.methodsMap.get(option.getOpt()).invoke(embeddedGobblin, option.getValue()); } else { this.methodsMap.get(option.getOpt()).invoke(embeddedGobblin); } } } catch (IllegalAccessException | InvocationTargetException exc) { throw new RuntimeException("Could not apply options to " + embeddedGobblin.getClass().getName(), exc); } }
final String argument = "--" + o.getLongOpt(); if (!o.hasArg()) { final Boolean flag = Boolean.parseBoolean(v);
if (option.hasArg() && (option.getArgName() == null || option.getArgName().length() != 0))
@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() ); }
currentOption = options.getOption(ch); if (currentOption.hasArg() && token.length() != i + 1)
@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() ); }
if (opt.hasArg())
private void logOptions(String sectionName, String prefix, Options options) { if ( sectionName != null ) { log.info("== " + sectionName + " =="); } //noinspection unchecked for ( Option option : (Iterable<? extends Option>)options.getOptions() ) { if ( option.hasLongOpt() ) { if ( option.hasArg() ) { log.info(prefix + option.getLongOpt() + " <arg> - " + option.getDescription()); } else { log.info(prefix + option.getLongOpt() + " - " + option.getDescription()); } } } }
if (option.hasArg())
private void handleOption(Option option) throws ParseException { // check the previous option before handling the next one checkRequiredArgs(); option = (Option) option.clone(); updateRequiredOptions(option); cmd.addOption(option); if (option.hasArg()) { currentOption = option; } else { currentOption = null; } }
if (opt.hasArg())
if (option.hasArg()) { final String argName = option.getArgName(); if (argName != null && argName.length() == 0) {
@Test public void testBaseOptionStringOpt() { Option base = OptionBuilder.withDescription( "option description") .create( "o" ); assertEquals( "o", base.getOpt() ); assertEquals( "option description", base.getDescription() ); assertTrue( !base.hasArg() ); }
@Test public void testBaseOptionCharOpt() { Option base = OptionBuilder.withDescription( "option description") .create( 'o' ); assertEquals( "o", base.getOpt() ); assertEquals( "option description", base.getDescription() ); assertTrue( !base.hasArg() ); }
if (opt.hasArg())
public Map.Entry<AMOptions, String> of(String value) { if(option.hasArg()) { return new AbstractMap.SimpleEntry<>(this, value); } return new AbstractMap.SimpleEntry<>(this, null); }