private void formatUsage(CommandManager mgr, StringBuffer buff, SubCommand cmd)
      throws CLIException {
    ResourceBundle rb = mgr.getResourceBundle();
    buff.append(rb.getString("USAGE"));
    buff.append("\n");

    buff.append(mgr.getCommandName()).append(" ").append(cmd.getName());

    formatOptionNames(cmd.getMandatoryOptions(), cmd, buff, CLIConstants.USAGE_OPTION_NAME_FORMAT);
    formatOptionNames(
        cmd.getOptionalOptions(), cmd, buff, CLIConstants.USAGE_OPTIONAL_OPTION_NAME_FORMAT);

    buff.append("\n").append("\n");
  }
  private void formatUsage(CommandManager mgr, StringBuffer buff) throws CLIException {
    ResourceBundle rb = mgr.getResourceBundle();
    String commandName = mgr.getCommandName();
    buff.append(rb.getString("USAGE"));
    buff.append("\n");

    for (Iterator i = globalArgs.iterator(); i.hasNext(); ) {
      try {
        String option = (String) i.next();
        Field fldLong = CLIConstants.class.getField(CLIConstants.PREFIX_ARGUMENT + option);
        Field fldShort = CLIConstants.class.getField(CLIConstants.PREFIX_SHORT_ARGUMENT + option);
        Object[] params = {
          commandName,
          fldLong.get(null),
          fldShort.get(null),
          rb.getString(CLIConstants.PREFIX_ARGUMENT + option)
        };
        buff.append(MessageFormat.format(CLIConstants.USAGE_FORMAT, params));
        buff.append("\n");
      } catch (Exception e) {
        throw new CLIException(e.getMessage(), ExitCodes.USAGE_FORMAT_ERROR);
      }
    }

    {
      Object[] params = {
        commandName,
        rb.getString("USAGE_SUBCOMMAND"),
        rb.getString("USAGE_GLOBAL_OPTIONS"),
        rb.getString("USAGE_OPTIONS"),
        rb.getString("ARGUMENT_SUBCOMMAND")
      };
      buff.append(MessageFormat.format(CLIConstants.USAGE_SUBCMD_FORMAT, params));
      buff.append("\n");
    }

    {
      Object[] params = {
        commandName,
        rb.getString("USAGE_SUBCOMMAND"),
        CLIConstants.ARGUMENT_HELP,
        CLIConstants.SHORT_ARGUMENT_HELP,
        rb.getString("ARGUMENT_SUBCOMMAND_HELP")
      };
      buff.append(MessageFormat.format(CLIConstants.USAGE_SUBCMD_HELP_FORMAT, params));
      buff.append("\n");
    }
  }
  /**
   * Prints the usage of sub command.
   *
   * @param mgr Command Manager object.
   * @param cmd Sub command object.
   * @throws CLIException if usage text cannot be presented.
   */
  public void format(CommandManager mgr, SubCommand cmd) throws CLIException {
    StringBuffer buff = new StringBuffer();
    buff.append("\n\n");

    ResourceBundle rb = mgr.getResourceBundle();
    String commandName = mgr.getCommandName();
    Object[] params = {
      commandName,
      cmd.getName(),
      rb.getString("USAGE_OPTIONS"),
      rb.getString("USAGE_GLOBAL_OPTIONS"),
      cmd.getDescription()
    };
    buff.append(MessageFormat.format(CLIConstants.USAGE_SUBCMD_LONG_FORMAT, params));
    buff.append("\n");
    formatUsage(mgr, buff, cmd);
    formatGlobalOptions(mgr, buff);
    formatOptions(mgr, buff, cmd);
    mgr.getOutputWriter().printlnMessage(buff.toString());
  }