Beispiel #1
0
  public <T> List<T> getTrailing(CliConverter<T> converter) {
    List<T> result = new ArrayList<>();

    for (String value : trailing) {
      try {
        result.add(converter.convert(value));
      } catch (Exception e) {
        throw new ErrorMessage(e, "Failed to parse %s", value);
      }
    }

    return result;
  }
Beispiel #2
0
  public <T> T get(String option, CliConverter<T> converter) {
    if (!switches.contains(option)) {
      throw new IllegalStateException(
          String.format("Expected option name to be one of %s, but got %s", switches, option));
    }

    String value = values.get(option);

    try {
      return converter.convert(value);
    } catch (Exception e) {
      throw new ErrorMessage(e, "Failed to parse %s %s", option, value);
    }
  }
Beispiel #3
0
  public <T> List<T> getMulti(String option, CliConverter<T> converter) {
    List<String> values = multiValues.get(option);

    if (values == null || values.isEmpty()) {
      // value must have been specified less than twice
      T value = get(option, converter);

      return value == null ? Collections.<T>emptyList() : Collections.singletonList(value);
    }

    List<T> result = new ArrayList<>();

    for (String value : values) {
      try {
        result.add(converter.convert(value));
      } catch (Exception e) {
        throw new ErrorMessage(e, "Failed to parse %s %s", option, value);
      }
    }

    return result;
  }