/** * Handles the following tokens: * <p/> * --L * -L * --l * -l * * @param token the command line token to handle */ private void handleLongOptionWithoutEqual(String token) throws CLIException { List<Option> matchingOpts = getMatchingOptions(token); if (matchingOpts.isEmpty()) { handleArgument(token); } else if (matchingOpts.size() > 1) { throw new AmbiguousOptionException(token, matchingOpts); } else { final Option option = matchingOpts.get(0); handleOption(option); } }
/** * Handles the following tokens: * <p/> * --L=V * -L=V * --l=V * -l=V * * @param token the command line token to handle */ private void handleLongOptionWithEqual(String token) throws CLIException { int pos = token.indexOf('='); String value = token.substring(pos + 1); String opt = token.substring(0, pos); List<Option> matchingOpts = getMatchingOptions(opt); if (matchingOpts.isEmpty()) { handleArgument(token); } else if (matchingOpts.size() > 1) { throw new AmbiguousOptionException(opt, matchingOpts); } else { Option option = matchingOpts.get(0); if (commandLine.acceptMoreValues(option)) { handleOption(option); commandLine.addRawValue(option, value); current = null; } else { throw new InvalidValueException(option, value); } } }
@Test public void testCreation() { AmbiguousOptionException exception = new AmbiguousOptionException("foo", Arrays.asList(new Option().setLongName("foobar"), new Option().setLongName("foobaz"))); assertThat(exception.getOptions()).hasSize(2); assertThat(exception.getToken()).isEqualTo("foo"); assertThat(exception.getMessage()) .contains("Ambiguous argument in command line") .contains("'foo'") .contains("foobar").contains("foobaz"); }
/** * Handles the following tokens: * <p/> * --L * -L * --l * -l * * @param token the command line token to handle */ private void handleLongOptionWithoutEqual(String token) throws CLIException { List<Option> matchingOpts = getMatchingOptions(token); if (matchingOpts.isEmpty()) { handleArgument(token); } else if (matchingOpts.size() > 1) { throw new AmbiguousOptionException(token, matchingOpts); } else { final Option option = matchingOpts.get(0); handleOption(option); } }
/** * Handles the following tokens: * <p/> * --L=V * -L=V * --l=V * -l=V * * @param token the command line token to handle */ private void handleLongOptionWithEqual(String token) throws CLIException { int pos = token.indexOf('='); String value = token.substring(pos + 1); String opt = token.substring(0, pos); List<Option> matchingOpts = getMatchingOptions(opt); if (matchingOpts.isEmpty()) { handleArgument(token); } else if (matchingOpts.size() > 1) { throw new AmbiguousOptionException(opt, matchingOpts); } else { Option option = matchingOpts.get(0); if (commandLine.acceptMoreValues(option)) { handleOption(option); commandLine.addRawValue(option, value); current = null; } else { throw new InvalidValueException(option, value); } } }
@Test public void testCreation() { AmbiguousOptionException exception = new AmbiguousOptionException("foo", Arrays.asList(new Option().setLongName("foobar"), new Option().setLongName("foobaz"))); assertThat(exception.getOptions()).hasSize(2); assertThat(exception.getToken()).isEqualTo("foo"); assertThat(exception.getMessage()) .contains("Ambiguous argument in command line") .contains("'foo'") .contains("foobar").contains("foobaz"); }