Ejemplo n.º 1
0
  private void formatSubcmds(CommandManager mgr, StringBuffer buff) throws CLIException {
    ResourceBundle rb = mgr.getResourceBundle();
    buff.append(rb.getString("USAGE_SUBCOMMAND_TITLE"));
    buff.append("\n");

    List defObjects = mgr.getDefinitionObjects();
    Map mapCmds = new HashMap();
    Set orderCmds = new TreeSet();

    for (Iterator i = defObjects.iterator(); i.hasNext(); ) {
      IDefinition def = (IDefinition) i.next();
      for (Iterator j = def.getSubCommands().iterator(); j.hasNext(); ) {
        SubCommand cmd = (SubCommand) j.next();

        if ((cmd != null) && (!mgr.webEnabled() || cmd.webEnabled())) {
          String name = cmd.getName();
          orderCmds.add(name);
          mapCmds.put(name, cmd.getDescription());
        }
      }
    }

    StringBuilder buffCmd = new StringBuilder();
    boolean started = false;
    String webEnabledURL = mgr.getWebEnabledURL();
    for (Iterator i = orderCmds.iterator(); i.hasNext(); ) {
      String cmdName = (String) i.next();
      buffCmd.append(formAbstractCmdUsage(webEnabledURL, cmdName, (String) mapCmds.get(cmdName)));
    }

    buff.append(buffCmd.toString());
  }
Ejemplo n.º 2
0
  /**
   * 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());
  }