Пример #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
 @Override
 @SuppressWarnings("unchecked")
 public <T> T getOptionValue(String name) {
   Option option = cli.getOption(name);
   if (option == null) {
     return null;
   }
   if (option instanceof TypedOption) {
     return getValue((TypedOption<T>) option);
   } else {
     return (T) getRawValueForOption(option);
   }
 }
Пример #3
0
 @Override
 @SuppressWarnings("unchecked")
 public <T> List<T> getOptionValues(String name) {
   Option option = cli.getOption(name);
   if (option == null) {
     return null;
   }
   if (option instanceof TypedOption) {
     TypedOption<T> typed = (TypedOption<T>) option;
     if (typed.isParsedAsList()) {
       return createFromList(getRawValueForOption(option), typed);
     } else {
       return getRawValuesForOption(option)
           .stream()
           .map(s -> create(s, typed))
           .collect(Collectors.toList());
     }
   } else {
     return (List<T>) getRawValuesForOption(option);
   }
 }