/** * Checks whether or not the user has passed a "help" option and is asking for help. * * @return {@code true} if the user command line has enabled a "Help" option, {@link false} * otherwise. */ @Override public boolean isAskingForHelp() { for (Option option : cli.getOptions()) { if (option.isHelp() && isSeenInCommandLine(option)) { return true; } } return false; }
@Override public boolean isFlagEnabled(String name) { Option option = cli.getOption(name); if (option == null) { throw new IllegalArgumentException("Cannot find the option '" + name + "'"); } if (option.isFlag()) { return optionsSeenInCommandLine.contains(option); } else { throw new IllegalStateException( "Cannot retrieve the flag value on a non-flag option (" + name + ")"); } }
@Override public String getRawValueForOption(Option option) { if (isOptionAssigned(option)) { return getRawValuesForOption(option).get(0); } return option.getDefaultValue(); }
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; }
@Override public boolean acceptMoreValues(Option option) { return option.isMultiValued() || option.isSingleValued() && !isOptionAssigned(option); }