code: public static Option[] parseCLArgs(String[] args, Option[] templates) {
          int i = 0;
          List<Option> options = new ArrayList<Option>(args.length);
  
          try {
              while (i < args.length) {
                  String name = args[i++];
                  Option template = findTemplate(name, templates);
                  StringBuilder values = new StringBuilder();
  
                  if (!Type.LIST.equals(template.getType())) {
                      for (int j = 0; j < template.getLen(); j++) {
                          values.append(args[i++]).append(" ");
                      }
                  } else if (hasMoreFlags(args, --i, templates)) {
                      throw new IllegalArgumentException();
                  } else {
                      for (String arg : Arrays.copyOfRange(args, i, args.length)) {
                          values.append(arg).append(" ");
                      }
                      template.setValue(values.toString().trim());
  
                      Option[] result = new Option[options.size() + 1];
  
                      result = options.toArray(result);
                      result[result.length - 1] = template;
                      return result;
                  }
                  template.setValue(values.toString().trim());
                  options.add(template);
              } // end while
              return options.toArray(new Option[options.size()]);
          } catch (Exception e) {
              throw new IllegalArgumentException(e);
          }
      }
docs: Parses the command line arguments of an application and compares those options against a list of expected options.
  
  @param   args       The command line arguments to parse
  @param   templates  The template list of application options.
  
  @return  A list of options that are present on the command line, are valid for the application and have data populated in them.
  
  @throws  IllegalArgumentException  If an error in processing occurs.