private boolean isAValidShortOption(String token) { String opt = token.substring(0, 1); Option option = getOption(opt); return option != null && commandLine.acceptMoreValues(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; }
private void handleOption(Option option) throws CLIException { // check the previous option before handling the next one checkRequiredValues(); updateRequiredOptions(option); //IMPORTANT for flag we must set this attributes as it will determine the value out of it. commandLine.setSeenInCommandLine(option); if (commandLine.acceptMoreValues(option)) { current = option; } else { current = null; } }
/** * 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); } } }
private void visit(String token) throws CLIException { this.token = token; if (skipParsing) { commandLine.addArgumentValue(token); } else if (token.equals("--")) { skipParsing = true; } else if (current != null && current.acceptValue() && isValue(token)) { commandLine.addRawValue(current, stripLeadingAndTrailingQuotes(token)); } else if (token.startsWith("--")) { handleLongOption(token); } else if (token.startsWith("-") && !"-".equals(token)) { handleShortAndLongOption(token); } else { handleArgument(token); } if (current != null && !commandLine.acceptMoreValues(current)) { current = null; } }
if (commandLine.acceptMoreValues(getOption(opt))) { handleOption(getOption(opt)); commandLine.addRawValue(getOption(opt), t.substring(opt.length())); if (commandLine.acceptMoreValues(option)) { handleOption(option); commandLine.addRawValue(option, value);
private boolean isAValidShortOption(String token) { String opt = token.substring(0, 1); Option option = getOption(opt); return option != null && commandLine.acceptMoreValues(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; }
private void handleOption(Option option) throws CLIException { // check the previous option before handling the next one checkRequiredValues(); updateRequiredOptions(option); //IMPORTANT for flag we must set this attributes as it will determine the value out of it. commandLine.setSeenInCommandLine(option); if (commandLine.acceptMoreValues(option)) { current = option; } else { current = null; } }
/** * 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); } } }
private void visit(String token) throws CLIException { this.token = token; if (skipParsing) { commandLine.addArgumentValue(token); } else if (token.equals("--")) { skipParsing = true; } else if (current != null && current.acceptValue() && isValue(token)) { commandLine.addRawValue(current, stripLeadingAndTrailingQuotes(token)); } else if (token.startsWith("--")) { handleLongOption(token); } else if (token.startsWith("-") && !"-".equals(token)) { handleShortAndLongOption(token); } else { handleArgument(token); } if (current != null && !commandLine.acceptMoreValues(current)) { current = null; } }
if (commandLine.acceptMoreValues(getOption(opt))) { handleOption(getOption(opt)); commandLine.addRawValue(getOption(opt), t.substring(opt.length())); if (commandLine.acceptMoreValues(option)) { handleOption(option); commandLine.addRawValue(option, value);