Example #1
0
  /**
   * Create a new commandline parser instance and scan all given object for supported options,
   * parameters and commands using the pre-registered default handlers. Please note that if you want
   * to use a custom set of option handlers, you should not give your config objects here but use
   * the {@link #addObject(Object...)} method after you registered the desired set of handlers.
   *
   * @param objects The configuration objects containing supported annotations.
   */
  public CmdlineParser(final Object... objects) {
    parent = null;
    programName = "<main class>";
    usageFormatter = new DefaultUsageFormatter(true, 80, new TtyLineLengthDetector());

    // ensure order by using a LinkedHashMap
    handlerRegistry = new LinkedHashMap<Class<? extends CmdOptionHandler>, CmdOptionHandler>();

    FList.foreach(
        defaultHandlers(),
        new Procedure1<CmdOptionHandler>() {
          @Override
          public void apply(final CmdOptionHandler h) {
            registerHandler(h);
          }
        });

    addObject(objects);
  }