Java Code Examples for org.kohsuke.args4j.spi.Parameters#getParameter()

The following examples show how to use org.kohsuke.args4j.spi.Parameters#getParameter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Closure_101_CommandLineRunner_s.java    From coming with MIT License 6 votes vote down vote up
@Override
public int parseArguments(Parameters params) throws CmdLineException {
  String param = params.getParameter(0);
  if (param == null) {
    setter.addValue(true);
    return 0;
  } else {
    String lowerParam = param.toLowerCase();
    if (TRUES.contains(lowerParam)) {
      setter.addValue(true);
    } else if (FALSES.contains(lowerParam)) {
      setter.addValue(false);
    } else {
      throw new CmdLineException(owner,
         "Illegal boolean value: " + lowerParam);
    }
    return 1;
  }
}
 
Example 2
Source File: Closure_101_CommandLineRunner_t.java    From coming with MIT License 6 votes vote down vote up
@Override
public int parseArguments(Parameters params) throws CmdLineException {
  String param = params.getParameter(0);
  if (param == null) {
    setter.addValue(true);
    return 0;
  } else {
    String lowerParam = param.toLowerCase();
    if (TRUES.contains(lowerParam)) {
      setter.addValue(true);
    } else if (FALSES.contains(lowerParam)) {
      setter.addValue(false);
    } else {
      throw new CmdLineException(owner,
         "Illegal boolean value: " + lowerParam);
    }
    return 1;
  }
}
 
Example 3
Source File: Closure_107_CommandLineRunner_t.java    From coming with MIT License 6 votes vote down vote up
@Override
public int parseArguments(Parameters params) throws CmdLineException {
  String param = null;
  try {
    param = params.getParameter(0);
  } catch (CmdLineException e) {
    param = null; // to stop linter complaints
  }

  if (param == null) {
    setter.addValue(true);
    return 0;
  } else {
    String lowerParam = param.toLowerCase();
    if (TRUES.contains(lowerParam)) {
      setter.addValue(true);
    } else if (FALSES.contains(lowerParam)) {
      setter.addValue(false);
    } else {
      setter.addValue(true);
      return 0;
    }
    return 1;
  }
}
 
Example 4
Source File: QueryMultiSetOptionHandler.java    From buck with Apache License 2.0 6 votes vote down vote up
/** Tries to parse {@code String[]} argument from {@link Parameters}. */
@Override
public int parseArguments(Parameters params) throws CmdLineException {
  int counter = 0;
  for (; counter < params.size(); counter++) {
    String param = params.getParameter(counter);

    // Special case the -- separator
    if (param.startsWith("-") && !param.equals(QueryNormalizer.SET_SEPARATOR)) {
      break;
    }

    setter.addValue(param);
  }

  return counter;
}
 
Example 5
Source File: Closure_83_CommandLineRunner_t.java    From coming with MIT License 6 votes vote down vote up
@Override
public int parseArguments(Parameters params) throws CmdLineException {
  String param = null;
  try {
    param = params.getParameter(0);
  } catch (CmdLineException e) {}

  if (param == null) {
    setter.addValue(true);
    return 0;
  } else {
    String lowerParam = param.toLowerCase();
    if (TRUES.contains(lowerParam)) {
      setter.addValue(true);
    } else if (FALSES.contains(lowerParam)) {
      setter.addValue(false);
    } else {
      setter.addValue(true);
      return 0;
    }
    return 1;
  }
}
 
Example 6
Source File: Closure_83_CommandLineRunner_s.java    From coming with MIT License 6 votes vote down vote up
@Override
public int parseArguments(Parameters params) throws CmdLineException {
  String param = params.getParameter(0);

  if (param == null) {
    setter.addValue(true);
    return 0;
  } else {
    String lowerParam = param.toLowerCase();
    if (TRUES.contains(lowerParam)) {
      setter.addValue(true);
    } else if (FALSES.contains(lowerParam)) {
      setter.addValue(false);
    } else {
      setter.addValue(true);
      return 0;
    }
    return 1;
  }
}
 
Example 7
Source File: BooleanOptionHandler.java    From MOE with Apache License 2.0 6 votes vote down vote up
@Override
public int parseArguments(Parameters params) throws CmdLineException {
  String param = null;
  try {
    param = params.getParameter(0);
  } catch (CmdLineException expected) {
  }

  if (param == null) {
    setter.addValue(true);
    return 0;
  } else {
    String lowerParam = param.toLowerCase();
    if (TRUES.contains(lowerParam)) {
      setter.addValue(true);
    } else if (FALSES.contains(lowerParam)) {
      setter.addValue(false);
    } else {
      setter.addValue(true);
      return 0;
    }
    return 1;
  }
}
 
Example 8
Source File: CommandLineRunner.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int parseArguments(Parameters params) throws CmdLineException {
  String param = null;
  try {
    param = params.getParameter(0);
  } catch (CmdLineException e) {}

  if (param == null) {
    setter.addValue(true);
    return 0;
  } else {
    String lowerParam = param.toLowerCase();
    if (TRUES.contains(lowerParam)) {
      setter.addValue(true);
    } else if (FALSES.contains(lowerParam)) {
      setter.addValue(false);
    } else {
      setter.addValue(true);
      return 0;
    }
    return 1;
  }
}
 
Example 9
Source File: EnumArrayOptionHandler.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
/**
 * Tries to parse {@code String[]} argument from {@link Parameters}.
 */
@Override
public int parseArguments(Parameters params)
    throws CmdLineException {
  int counter = 0;
  for (; counter < params.size(); counter++) {
    String param = params.getParameter(counter);

    if (param.startsWith("-")) {
      break;
    }

    for (String p : param.split(" ")) {
      Class<T> t = (Class<T>) setter.getType();
      setter.addValue(Enum.valueOf(t, p));
    }
  }

  return counter;
}
 
Example 10
Source File: StringSetOptionHandler.java    From buck with Apache License 2.0 6 votes vote down vote up
@Override
public int parseArguments(Parameters params) throws CmdLineException {
  int counter = 0;
  boolean hasValues = false;

  while (counter < params.size()) {
    String param = params.getParameter(counter);
    if (!param.isEmpty() && param.charAt(0) == '-') {
      break;
    }
    hasValues = true;
    builder.add(param);
    counter++;
  }

  Preconditions.checkArgument(hasValues, "Option \"%s\" takes one or more operands", option);
  return counter;
}
 
Example 11
Source File: TestSelectorOptions.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public int parseArguments(Parameters parameters) throws CmdLineException {
  String rawTestSelector = parameters.getParameter(0);
  try {
    builder.addRawSelectors(rawTestSelector);
  } catch (TestSelectorParseException e) {
    String message = "Unable to parse test selectors: " + e.getMessage();
    throw new HumanReadableException(e, message);
  }
  return 1;
}
 
Example 12
Source File: Compression.java    From monsoon with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public int parseArguments(Parameters prmtrs) throws CmdLineException {
    final String valueStr = prmtrs.getParameter(0);
    final Optional<Compression> compress = Arrays.stream(Compression.values())
            .filter(cmp -> cmp.humanName.equals(valueStr))
            .findFirst();
    if (compress.isPresent()) {
        setter.addValue(compress.get());
        return 1;
    }
    throw new CmdLineException(owner, ILLEGAL_COMPRESSION, valueStr, COMMA_SEPARATED_VALID_OPTIONS);
}
 
Example 13
Source File: ZooKeeperPathOptionHandler.java    From zoocreeper with Apache License 2.0 5 votes vote down vote up
@Override
public int parseArguments(Parameters params) throws CmdLineException {
    String param = params.getParameter(0);
    try {
        PathUtils.validatePath(param);
        setter.addValue(param);
        return 1;
    } catch (IllegalArgumentException e) {
        throw new CmdLineException(owner,
                String.format("\"%s\" is not a valid value for \"%s\"", param, params.getParameter(-1)));
    }
}
 
Example 14
Source File: SingleStringSetOptionHandler.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public int parseArguments(Parameters params) throws CmdLineException {
  String p = params.getParameter(0);
  if (p.isEmpty()) {
    throw new CmdLineException(String.format("Option \"%s\" takes one operand", option));
  }
  if (p.startsWith("-")) {
    throw new CmdLineException(String.format("Option \"%s\" takes one operand", option));
  }
  builder.add(p);
  return 1;
}
 
Example 15
Source File: TestLabelOptions.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public int parseArguments(Parameters parameters) throws CmdLineException {
  int index;
  for (index = 0; index < parameters.size(); index++) {
    String parameter = parameters.getParameter(index);
    if (parameter.charAt(0) == '-') {
      break;
    }
    labels.put(ordinal.getAndIncrement(), LabelSelector.fromString(parameter));
  }
  return index;
}
 
Example 16
Source File: RegexOptionHandler.java    From zoocreeper with Apache License 2.0 5 votes vote down vote up
@Override
public int parseArguments(Parameters params) throws CmdLineException {
    final String regex = params.getParameter(0);
    try {
        final Pattern pattern = Pattern.compile(regex);
        setter.addValue(pattern);
    } catch (PatternSyntaxException e) {
        throw new CmdLineException(owner, "Invalid regular expression: " + regex, e);
    }
    return 1;
}
 
Example 17
Source File: Options.java    From clutz with MIT License 5 votes vote down vote up
@Override
public int parseArguments(Parameters params) throws CmdLineException {
  final int paramsSize = params.size();
  for (int i = 0; i < paramsSize; i++) {
    String param = params.getParameter(i);
    if (param.startsWith("-")) {
      return i;
    }

    setter.addValue(param);
  }
  return paramsSize;
}
 
Example 18
Source File: CommandLineParameters.java    From amidst with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int parseArguments(Parameters params) throws CmdLineException {
    String param = params.getParameter(0);
    WorldType type = WorldType.findInstance(param);
    if(type == null) {
        throw new CmdLineException(owner, "Invalid WorldType: '" + param + "'", null);
    }
    setter.addValue(type);
    return 1;
}
 
Example 19
Source File: CommandLineParameters.java    From amidst with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int parseArguments(Parameters params) throws CmdLineException {
    String param = params.getParameter(0);
    WorldType type = WorldType.findInstance(param);
    if(type == null) {
        throw new CmdLineException(owner, "Invalid WorldType: '" + param + "'", null);
    }
    setter.addValue(type);
    return 1;
}
 
Example 20
Source File: IjProjectSubCommand.java    From buck with Apache License 2.0 4 votes vote down vote up
@Override
public int parseArguments(Parameters params) throws CmdLineException {
  String param = params.getParameter(0);
  setter.addValue(AggregationMode.fromString(param));
  return 1;
}