Java 类org.kohsuke.args4j.spi.Parameters 实例源码

项目:feedlack    文件:CommandLineRunner.java   
@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;
  }
}
项目:chordelia    文件:KombinationsberechnungParameterJaNeinOptionHandler.java   
@Override
public int parseArguments(Parameters params) throws CmdLineException {
  log.info("Parsing: " + params);
  // Different compared to BooleanOptionHandler
  if (!option.isArgument()) {
    String valueStr = params.getParameter(0).toLowerCase();
    int index = ACCEPTABLE_VALUES.indexOf(valueStr);
    if (index == -1) {
      // TODO Check
      Localizable localizable = null;
      throw new CmdLineException(theParser, localizable, Messages.ILLEGAL_BOOLEAN.format(valueStr));
    }
    setter.addValue(index < ACCEPTABLE_VALUES.size() / 2);
    return 1;
  } else {
    setter.addValue(true);
    return 0;
  }
}
项目:hyst    文件:StringWithSpacesArrayOptionHandler.java   
/**
 * 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);

        boolean nextAlpha = false;

        if (param.length() > 1 && Character.isAlphabetic(param.charAt(1)))
            nextAlpha = true;

        if (param.startsWith("-") && nextAlpha)
            break;

        setter.addValue(param);
    }

    return counter;
}
项目:heroic    文件:OptionalOptionHandler.java   
@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);
}
项目:js-symbolic-executor    文件:CommandLineRunner.java   
@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;
  }
}
项目:gerrit    文件:GetDiff.java   
@Override
public final int parseArguments(Parameters params) throws CmdLineException {
  final String value = params.getParameter(0);
  short context;
  if ("all".equalsIgnoreCase(value)) {
    context = DiffPreferencesInfo.WHOLE_FILE_CONTEXT;
  } else {
    try {
      context = Short.parseShort(value, 10);
      if (context < 0) {
        throw new NumberFormatException();
      }
    } catch (NumberFormatException e) {
      throw new CmdLineException(
          owner,
          String.format(
              "\"%s\" is not a valid value for \"%s\"",
              value, ((NamedOptionDef) option).name()));
    }
  }
  setter.addValue(context);
  return 1;
}
项目:MOE    文件:BooleanOptionHandler.java   
@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;
  }
}
项目:astor    文件:CommandLineRunner.java   
@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;
  }
}
项目:closure-compiler    文件:CommandLineRunner.java   
@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 = Ascii.toLowerCase(param);
    if (TRUES.contains(lowerParam)) {
      setter.addValue(true);
    } else if (FALSES.contains(lowerParam)) {
      setter.addValue(false);
    } else {
      setter.addValue(true);
      return 0;
    }
    return 1;
  }
}
项目:closure-templates    文件:SoyCmdLineParser.java   
@Override
public int parseArguments(Parameters params) throws CmdLineException {
  String parameter = params.getParameter(0);
  // An empty string should be null
  if (parameter.isEmpty()) {
    setter.addValue(null);
  } else {
    setter.addValue(
        instantiateObject(
            ((NamedOptionDef) option).name(),
            "plugin module",
            Module.class,
            ((SoyCmdLineParser) this.owner).pluginLoader,
            parameter));
  }
  return 1;
}
项目:closure-templates    文件:SoyCmdLineParser.java   
@Override
public int parseArguments(Parameters params) throws CmdLineException {
  String parameter = params.getParameter(0);
  // An empty string should be null
  if (parameter.isEmpty()) {
    setter.addValue(null);
  } else {
    setter.addValue(
        instantiateObject(
            ((NamedOptionDef) option).name(),
            "msg plugin",
            SoyMsgPlugin.class,
            ((SoyCmdLineParser) this.owner).pluginLoader,
            parameter));
  }
  return 1;
}
项目:dumpling    文件:CliCommandOptionHandler.java   
@Override
public int parseArguments(Parameters params) throws CmdLineException {
    String name = params.getParameter(0);
    CliCommand handler = getHandler(name);

    if (handler == null) throw new CmdLineException(
            owner, "Command \"" + name + "\" not found"
    );

    setter.addValue(handler);

    // Collect subcommand arguments
    int paramCount = params.size();
    String[] subCommandParams = new String[paramCount - 1];
    for (int i = 1; i < paramCount; i++) {
        subCommandParams[i - 1] = params.getParameter(i);
    }
    new CmdLineParser(handler).parseArgument(subCommandParams);

    return params.size(); // All arguments consumed
}
项目:closure-compiler-old    文件:CommandLineRunner.java   
@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;
  }
}
项目:buck    文件:StringSetOptionHandler.java   
@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;
}
项目:buck    文件:QueryMultiSetOptionHandler.java   
/** 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(QueryCommand.SET_SEPARATOR)) {
      break;
    }

    setter.addValue(param);
  }

  return counter;
}
项目:closure-compiler-copy    文件:CommandLineRunner.java   
@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;
  }
}
项目:JavaGraph    文件:PrologChecker.java   
@Override
public int parseArguments(Parameters params) throws CmdLineException {
    ArrayList<String> genArgs = new ArrayList<>();
    for (int ix = 0; ix < params.size(); ix++) {
        genArgs.add(params.getParameter(ix));
    }
    this.setter.addValue(new GeneratorArgs(params));
    return params.size();
}
项目:JavaGraph    文件:CTLModelChecker.java   
@Override
public int parseArguments(Parameters params) throws CmdLineException {
    ArrayList<String> genArgs = new ArrayList<>();
    for (int ix = 0; ix < params.size(); ix++) {
        genArgs.add(params.getParameter(ix));
    }
    this.setter.addValue(new GeneratorArgs(params));
    return params.size();
}
项目:ibench    文件:Log4jLevelOptionHandler.java   
@Override
public int parseArguments(Parameters params) throws CmdLineException {
    if (params.size() != 1)
        throw new CmdLineException ("an option of type log level should have one parameter [trace,debug,info,warn,error,fatal,off]");
    Level result = Level.toLevel(params.getParameter(0).toLowerCase());
    setter.addValue(result);
    log.debug("set log level " + result);
    return 1;
}
项目:monsoon    文件:ManyInetAddressOptionHandler.java   
@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);
    }
}
项目:monsoon    文件:BytesParser.java   
@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.
}
项目:monsoon    文件:InetAddressOptionHandler.java   
@Override
public int parseArguments(Parameters prmtrs) throws CmdLineException {
    final HostnamePort hp = HostnamePort.valueOf(prmtrs.getParameter(0), defaultPort());

    setter.addValue(hp.getAddress());
    return 1;
}
项目:monsoon    文件:Compression.java   
@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);
}
项目:HeliosStreams    文件:JMXMPSpecOptionHandler.java   
/**
 * {@inheritDoc}
 * @see org.kohsuke.args4j.spi.OptionHandler#parseArguments(org.kohsuke.args4j.spi.Parameters)
 */
@Override
public int parseArguments(final Parameters parameters) throws CmdLineException {
    final Set<JMXMPSpec> specs = new LinkedHashSet<JMXMPSpec>();
    final JMXMPSpec[] jspec = JMXMPSpec.parse(parameters.getParameter(0));
    Collections.addAll(specs, jspec);       
    if(specs.isEmpty()) specs.add(new JMXMPSpec());
    final JMXMPSpec[] jspecs = specs.toArray(new JMXMPSpec[specs.size()]);
    setter.addValue(jspecs);
    return 1;
}
项目:hyst    文件:StringPairsWithSpacesArrayOptionHandler.java   
/**
 * Tries to parse {@code String[]} argument from {@link Parameters}.
 */
@SuppressWarnings("deprecation")
@Override
public int parseArguments(Parameters params) throws CmdLineException
{
    int counter = 0;
    for (; counter < params.size(); counter += 2)
    {
        String param1 = params.getParameter(counter);

        if (param1.startsWith("-"))
        {
            if (counter == 0)
            {
                // deprecated: we don't have proper locale support in Hyst
                throw new CmdLineException(owner,
                        "No arguments found after a flag which requires arguments: "
                                + option.toString());
            }

            break;
        }

        if (counter + 1 == params.size())
        {
            // deprecated: we don't have proper locale support in Hyst
            throw new CmdLineException(owner,
                    "Excepted pairs of arguments for option '" + option.toString() + "'.");
        }

        String param2 = params.getParameter(counter + 1);

        setter.addValue(param1);
        setter.addValue(param2);
    }

    return counter;
}
项目:hyst    文件:DoubleArrayOptionHandler.java   
/**
 * Tries to parse {@code Double[]} argument from {@link Parameters}.
 */
@SuppressWarnings("deprecation") // we don't have proper locale support in
                                    // Hyst
@Override
public int parseArguments(Parameters params) throws CmdLineException
{
    int counter = 0;

    for (; counter < params.size(); counter++)
    {
        String param = params.getParameter(counter);

        // negative numbers should be okay, but we should break if it's a
        // flag
        if (param.startsWith("-")
                && (param.length() < 2 || !Character.isDigit(param.charAt(1))))
            break;

        try
        {
            setter.addValue(Double.parseDouble(param));
        }
        catch (NumberFormatException e)
        {
            // deprecated: we don't have proper locale support in Hyst
            throw new CmdLineException(owner,
                    "Error parsing argument as number: '" + param + "'");
        }
    }

    return counter;
}
项目:hyst    文件:ExpressionValueArrayOptionHandler.java   
/**
 * Tries to parse {@code Expression[]} argument from {@link Parameters}.
 */
@SuppressWarnings("deprecation") // we don't have proper locale support in
                                    // Hyst
@Override
public int parseArguments(Parameters params) throws CmdLineException
{
    int counter = 0;

    for (; counter < params.size(); counter++)
    {
        String param = params.getParameter(counter);

        // negative numbers should be okay, but we should break if it's a
        // flag
        // use parenthesis around -varName expressions to resolve ambiguity
        if (param.startsWith("-")
                && (param.length() < 2 || !Character.isDigit(param.charAt(1))))
            break;

        try
        {
            setter.addValue(FormulaParser.parseValue(param));
        }
        catch (AutomatonExportException e)
        {
            // deprecated: we don't have proper locale support in Hyst
            throw new CmdLineException(owner, "Error parsing argument as value expression: '"
                    + param + "': " + e.toString());
        }
    }

    return counter;
}
项目:hyst    文件:PairStringOptionHandler.java   
/**
 * Tries to parse {@code Double[]} argument from {@link Parameters}.
 */
@SuppressWarnings("deprecation") // we don't have proper locale support in
                                    // Hyst
@Override
public int parseArguments(Parameters params) throws CmdLineException
{
    int counter = 0;

    for (; counter < params.size(); counter += 2)
    {
        String param1 = params.getParameter(counter);

        if (param1.startsWith("-"))
        {
            if (counter == 0)
            {
                // deprecated: we don't have proper locale support in Hyst
                throw new CmdLineException(owner,
                        "No arguments found after a flag which requires arguments: "
                                + option.toString());
            }

            break;
        }

        if (counter + 1 == params.size())
        {
            // deprecated: we don't have proper locale support in Hyst
            throw new CmdLineException(owner,
                    "Excepted pairs of arguments. Argument missing after option '"
                            + option.toString() + "'.");
        }

        String param2 = params.getParameter(counter + 1);

        setter.addValue(new String[] { param1, param2 });
    }

    return counter;
}
项目:clutz    文件:Options.java   
@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;
}
项目:gerrit    文件:TimestampHandler.java   
@Override
public int parseArguments(Parameters params) throws CmdLineException {
  String timestamp = params.getParameter(0);
  try {
    DateFormat fmt = new SimpleDateFormat(TIMESTAMP_FORMAT);
    fmt.setTimeZone(TimeZone.getTimeZone("UTC"));
    setter.addValue(new Timestamp(fmt.parse(timestamp).getTime()));
    return 1;
  } catch (ParseException e) {
    throw new CmdLineException(
        owner,
        String.format("Invalid timestamp: %s; expected format: %s", timestamp, TIMESTAMP_FORMAT),
        e);
  }
}
项目:gerrit    文件:PatchSetIdHandler.java   
@Override
public final int parseArguments(Parameters params) throws CmdLineException {
  final String token = params.getParameter(0);
  final PatchSet.Id id;
  try {
    id = PatchSet.Id.parse(token);
  } catch (IllegalArgumentException e) {
    throw new CmdLineException(owner, "\"" + token + "\" is not a valid patch set");
  }

  setter.addValue(id);
  return 1;
}
项目:gerrit    文件:AccountGroupUUIDHandler.java   
@Override
public final int parseArguments(Parameters params) throws CmdLineException {
  final String n = params.getParameter(0);
  GroupReference group = GroupBackends.findExactSuggestion(groupBackend, n);
  if (group == null) {
    throw new CmdLineException(owner, "Group \"" + n + "\" does not exist");
  }
  setter.addValue(group.getUUID());
  return 1;
}
项目:gerrit    文件:AccountGroupIdHandler.java   
@Override
public final int parseArguments(Parameters params) throws CmdLineException {
  final String n = params.getParameter(0);
  Optional<InternalGroup> group = groupCache.get(new AccountGroup.NameKey(n));
  if (!group.isPresent()) {
    throw new CmdLineException(owner, "Group \"" + n + "\" does not exist");
  }
  setter.addValue(group.get().getId());
  return 1;
}
项目:gerrit    文件:SocketAddressHandler.java   
@Override
public final int parseArguments(Parameters params) throws CmdLineException {
  final String token = params.getParameter(0);
  try {
    setter.addValue(SocketUtil.parse(token, 0));
  } catch (IllegalArgumentException e) {
    throw new CmdLineException(owner, e.getMessage());
  }
  return 1;
}
项目:openimaj    文件:MBFImageOptionHandler.java   
@Override
public int parseArguments(Parameters params) throws CmdLineException {
    File file = new File(params.getParameter(0));
    try {
        setter.addValue(ImageUtilities.readMBF(file));
    } catch (IOException e) {
        throw new CmdLineException(owner, "Error opening image file " + file, e);
    }

    return 1;
}
项目:openimaj    文件:FImageOptionHandler.java   
@Override
public int parseArguments(Parameters params) throws CmdLineException {
    File file = new File(params.getParameter(0));
    try {
        setter.addValue(ImageUtilities.readF(file));
    } catch (IOException e) {
        throw new CmdLineException(owner, "Error opening image file " + file, e);
    }

    return 1;
}
项目:openimaj    文件:ProxyOptionHandler.java   
@Override
public int parseArguments(Parameters params) throws CmdLineException {
    if (CmdLineOptionsProvider.class.isAssignableFrom(this.setter.getType())) {
        removeExtraArgs();
    }

    int val = proxy.parseArguments(params);

    if (CmdLineOptionsProvider.class.isAssignableFrom(this.setter.getType())) {
        handleExtraArgs();
    }

    return val;
}
项目:openimaj    文件:FileOutputStreamOptionHandler.java   
@Override
public int parseArguments(Parameters params) throws CmdLineException {
    File file = new File(params.getParameter(0));
    try {
        setter.addValue(new FileOutputStream(file));
    } catch (IOException e) {
        throw new CmdLineException(owner, "Error opening stream to output file " + file, e);
    }

    return 1;
}
项目:JMXMPAgent    文件:JMXMPSpecOptionHandler.java   
/**
 * {@inheritDoc}
 * @see org.kohsuke.args4j.spi.OptionHandler#parseArguments(org.kohsuke.args4j.spi.Parameters)
 */
@Override
public int parseArguments(final Parameters parameters) throws CmdLineException {
    final Set<JMXMPSpec> specs = new LinkedHashSet<JMXMPSpec>();
    final JMXMPSpec[] jspec = JMXMPSpec.parse(parameters.getParameter(0));
    Collections.addAll(specs, jspec);       
    if(specs.isEmpty()) specs.add(new JMXMPSpec());
    final JMXMPSpec[] jspecs = specs.toArray(new JMXMPSpec[specs.size()]);
    setter.addValue(jspecs);
    return 1;
}
项目:closure-templates    文件:SoyCmdLineParser.java   
@Override
public int parseArguments(Parameters params) throws CmdLineException {

  boolean value;
  boolean hasParam;
  try {
    String nextArg = params.getParameter(0);
    if (nextArg.equalsIgnoreCase("true") || nextArg.equals("1")) {
      value = true;
      hasParam = true;
    } else if (nextArg.equalsIgnoreCase("false") || nextArg.equals("0")) {
      value = false;
      hasParam = true;
    } else {
      // Next arg is not a param for this flag. No param means set flag to true.
      value = true;
      hasParam = false;
    }
  } catch (CmdLineException e) {
    // No additional args on command line. No param means set flag to true.
    value = true;
    hasParam = false;
  }

  setter.addValue(value);
  return hasParam ? 1 : 0;
}