/** * Creates a new instance of {@link MissingValueException} when an option requiring a value does not receive a value. * * @param option the option */ public MissingValueException(Option option) { super("The option '" + option.getName() + "' requires a value"); this.argument = null; this.option = option; }
/** * Creates a new instance of {@link InvalidValueException} for the given option and the given value. This * constructor is used when the options receives a value that cannot be "converted" to the desired type. * * @param option the option * @param value the value * @param cause the cause */ public InvalidValueException(Option option, String value, Exception cause) { super("The value '" + value + "' is not accepted by '" + option.getName() + "'", cause); this.argument = null; this.value = value; this.option = option; }
public DefaultCommandLine addRawValue(Option option, String value) { if (!acceptMoreValues(option) && !option.isFlag()) { throw new CLIException("The option " + option.getName() + " does not accept value or has " + "already been set"); } if (! option.getChoices().isEmpty() && ! option.getChoices().contains(value)) { throw new InvalidValueException(option, value); } List<String> list = optionValues.get(option); if (list == null) { list = new ArrayList<>(); optionValues.put(option, list); } list.add(value); return this; }
@Test public void testOptionsWithDefaultValue() { CLI cli = CLIConfigurator.define(CommandForDefaultValueTest.class); assertThat(cli.getOptions()).hasSize(1); assertThat(find(cli.getOptions(), "option").getDefaultValue()).isEqualTo("bar"); assertThat(find(cli.getOptions(), "option").getName()).isEqualTo("option"); }
/** * Creates a new instance of {@link MissingValueException} when an option requiring a value does not receive a value. * * @param option the option */ public MissingValueException(Option option) { super("The option '" + option.getName() + "' requires a value"); this.argument = null; this.option = option; }
/** * Creates a new instance of {@link InvalidValueException} for the given option and the given value. This * constructor is used when the options receives a value that cannot be "converted" to the desired type. * * @param option the option * @param value the value * @param cause the cause */ public InvalidValueException(Option option, String value, Exception cause) { super("The value '" + value + "' is not accepted by '" + option.getName() + "'", cause); this.argument = null; this.value = value; this.option = option; }
public DefaultCommandLine addRawValue(Option option, String value) { if (!acceptMoreValues(option) && !option.isFlag()) { throw new CLIException("The option " + option.getName() + " does not accept value or has " + "already been set"); } if (! option.getChoices().isEmpty() && ! option.getChoices().contains(value)) { throw new InvalidValueException(option, value); } List<String> list = optionValues.get(option); if (list == null) { list = new ArrayList<>(); optionValues.put(option, list); } list.add(value); return this; }
@Test public void testOptionsWithDefaultValue() { CLI cli = CLIConfigurator.define(CommandForDefaultValueTest.class); assertThat(cli.getOptions()).hasSize(1); assertThat(find(cli.getOptions(), "option").getDefaultValue()).isEqualTo("bar"); assertThat(find(cli.getOptions(), "option").getName()).isEqualTo("option"); }