Ejemplo n.º 1
0
  public void parse(String[] args) throws Exception {
    Assert.preCondition(args != null);

    if (this.commandLineSpec.getRequiredArgNum() > args.length) this.helpHandler.handleHelp();

    int compulsoryArgs = 0;
    int i = 0;
    ArgSpec spec;
    String arg;

    while (i < args.length) {
      while (args[i].startsWith(argumentPrefix) == false) i++;

      // Now we have the first desired arg.
      arg = args[i].substring(argumentPrefix.length());

      if (this.isHelpArg(arg)) this.helpHandler.handleHelp();

      spec = this.commandLineSpec.getArg(arg);

      if (spec == null) {
        spec = this.commandLineSpec.getRequiredArg(arg);
        if (spec == null) break;

        // Make sure that the repetition of the same argument
        // does not get counted more than once.
        if (this.argList.get(arg) == null) compulsoryArgs++;
      }

      ArgValue argVal = new ArgValue(spec, args, ++i, spec.argNum());
      this.argList.put(spec.getName(), argVal);
      argVal = null;
      i += spec.argNum();
    }

    if (compulsoryArgs < this.commandLineSpec.getRequiredArgNum()) {
      this.helpHandler.handleHelp();
      //   throw new InvalidArgumentValueException("Required Argument Missing!");
    }
  }
Ejemplo n.º 2
0
 public ArgValue getArg(ArgSpec spec) throws AssertionException {
   Assert.preCondition(spec != null);
   return (ArgValue) this.argList.get(spec.getName());
 }