org.kohsuke.args4j.spi.Parameters Java Examples

The following examples show how to use org.kohsuke.args4j.spi.Parameters. 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: 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 #2
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 #3
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 #4
Source File: Closure_107_CommandLineRunner_s.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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
Source File: OptionalOptionHandler.java    From heroic with Apache License 2.0 6 votes vote down vote up
@Override
public int parseArguments(Parameters params) throws CmdLineException {
    if (type.equals(STRING)) {
        setter.addValue(Optional.of(params.getParameter(0)));
        return 1;
    }

    if (type.equals(PATH)) {
        final Path p = Paths.get(params.getParameter(0));
        setter.addValue(Optional.of(p));
        return 1;
    }

    if (type.equals(INTEGER)) {
        setter.addValue(Optional.of(Integer.parseInt(params.getParameter(0))));
        return 1;
    }

    if (type.equals(LONG)) {
        setter.addValue(Optional.of(Long.parseLong(params.getParameter(0))));
        return 1;
    }

    throw new IllegalArgumentException("Unsupported type: " + type);
}
 
Example #11
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 #12
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 #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: 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 #15
Source File: ListGpuParameterHandler.java    From sheepit-client with GNU General Public License v2.0 5 votes vote down vote up
@Override public int parseArguments(Parameters params) throws CmdLineException {
	List<GPUDevice> gpus = GPU.listDevices(new Configuration(null, null, null));
	if (gpus != null) {
		for (GPUDevice gpu : gpus) {
			System.out.println("GPU_ID    : " + gpu.getOldId());
			System.out.println("Long ID   : " + gpu.getId());
			System.out.println("Model     : " + gpu.getModel());
			System.out.println("Memory, MB: " + (int) (gpu.getMemory() / (1024 * 1024)));
			System.out.println();
		}
	}
	
	System.exit(0);
	return 0;
}
 
Example #16
Source File: ConsumeAllOptionsHandler.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public int parseArguments(Parameters params) throws CmdLineException {
  for (int idx = 0; idx < params.size(); idx += 1) {
    setter.addValue(params.getParameter(idx));
  }
  return params.size();
}
 
Example #17
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 #18
Source File: PairedStringOptionHandler.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public int parseArguments(Parameters params) throws CmdLineException {
  String parameter1 = getParamAndValidate(params, 0);
  String parameter2 = getParamAndValidate(params, 1);
  setter.addValue(new Pair<>(parameter1, parameter2));
  return 2;
}
 
Example #19
Source File: PairedStringOptionHandler.java    From buck with Apache License 2.0 5 votes vote down vote up
private String getParamAndValidate(Parameters params, int idx) throws CmdLineException {
  String param = params.getParameter(idx);

  if (param.isEmpty() || param.startsWith("-")) {
    throw new CmdLineException(
        String.format(
            "Option \"%s\" takes exactly 2 values (found \"%s\" at position %s)",
            option, param, idx));
  }

  return param;
}
 
Example #20
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 #21
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 #22
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 #23
Source File: N4jscGoal.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public int parseArguments(Parameters params) throws CmdLineException {
	try {
		return delegate.parseArguments(params);
	} catch (CmdLineException e) {
		// This exception is thrown in case no goal was given
		return 0;
	}
}
 
Example #24
Source File: ManyInetAddressOptionHandler.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 HostnamePort hp = HostnamePort.valueOf(prmtrs.getParameter(0), defaultPort());

    try {
        for (InetSocketAddress addr : hp.getAddressList())
            setter.addValue(addr);
        return 1;
    } catch (UnknownHostException ex) {
        throw new CmdLineException(owner, "unable to resolve " + hp.getHostname(), ex);
    }
}
 
Example #25
Source File: BytesParser.java    From monsoon with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public int parseArguments(Parameters params) throws CmdLineException {
    final long value;
    try {
        value = parse(params.getParameter(0));
    } catch (IllegalArgumentException ex) {
        throw new CmdLineException(owner, "unable to parse size", ex);
    }

    setter.addValue(value);
    return 1;  // 1 argument consumed.
}
 
Example #26
Source File: InetAddressOptionHandler.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 HostnamePort hp = HostnamePort.valueOf(prmtrs.getParameter(0), defaultPort());

    setter.addValue(hp.getAddress());
    return 1;
}
 
Example #27
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 #28
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 #29
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 #30
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;
}