Esempio n. 1
0
 public Object tryArgument(String arg) throws Exception {
   try {
     ArrayList<Object> retval = new ArrayList<Object>();
     String[] values = arg.split(separator);
     if (values.length == 0) {
       throw new Exception("Invalid argument");
     }
     if (values.length == 1) {
       return handler.tryArgument(values[0]);
     }
     if (values.length > maxEntries) {
       throw new Exception(String.format("Cannot exceed %d entries", maxEntries));
     }
     for (String v : values) {
       Object param = handler.tryArgument(v);
       if (param == null) {
         throw new Exception(String.format("Invalid member of list: %s", v));
       }
       retval.add(param);
     }
     return retval;
   } catch (Exception e) {
     throw e;
   }
 }
Esempio n. 2
0
    public String toUsageString(String prepend) {
      StringBuilder builder = new StringBuilder();

      builder.append(prepend);
      builder.append(String.format("%s: %s", name, description));
      builder.append("\n");

      if (defaultValue != null) {
        builder.append(prepend);
        builder.append(String.format("\tDefault: %s", defaultValue.toString()));
        builder.append("\n");
      }

      String handlerUsage = handler.toUsageString(prepend);
      if (handlerUsage != null && handlerUsage.length() > 0) {
        builder.append("\t");
        builder.append(handlerUsage);
        builder.append("\n");
      }

      return builder.toString();
    }