예제 #1
0
 public String usage() {
   String progName = mProgName != null ? mProgName : "progname";
   String optsString1 =
       (mValidOptionNames != null && mValidOptionNames.size() > 0) ? " <options>" : "";
   String nonOptArgsString =
       (mNonOptParamNames != null && mNonOptParamNames.size() > 0)
           ? " <" + StringUtils.listToString(mNonOptParamNames, "> <") + ">"
           : "";
   String optsString2 =
       (mValidOptionNames != null && mValidOptionNames.size() > 0)
           ? "\nOPTIONS:\n" + optsWithValString() + "\n" + optsWithoutValString()
           : "";
   return "Usage: " + progName + optsString1 + nonOptArgsString + optsString2;
 }
예제 #2
0
  public void addDef(OptDef pDef) {

    mArgDefs.add(pDef);

    if (mShortNameToLongNameMap.containsKey(pDef.shortname)) {
      throw new RuntimeException("Duplicate short name: " + pDef.shortname);
    }

    mValidOptionNames.add(pDef.longname);

    if (pDef.shortname != null) {
      mValidOptionNames.add(pDef.shortname);
      mShortNameToLongNameMap.put(pDef.shortname, pDef.longname);
    } else {
      mOptionsWithoutShortName.add(pDef.longname);
    }

    if (pDef.hasvalue) {
      mNamesOfOptionsRequiringValue.add(pDef.longname);
    }

    if (pDef.defaultvalue != null) {
      // a little sanity check, if you permit...
      if (!(pDef.hasvalue)) {
        throw new RuntimeException(
            "Illegal situation: parameter "
                + pDef.longname
                + " has no value, "
                + "but still has default value "
                + pDef.defaultvalue);
      }
      mDefaultValues.put(pDef.longname, pDef.defaultvalue);
    }

    if (pDef.possiblevalues != null) {
      // for an "enum" type parameter
      mPossibleValues.putMultiple(pDef.longname, pDef.possiblevalues);
    }
  }