コード例 #1
0
 @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 + ")");
   }
 }
コード例 #2
0
 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;
 }