Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 75851 invoked from network); 10 Nov 2007 06:20:36 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 10 Nov 2007 06:20:36 -0000 Received: (qmail 30818 invoked by uid 500); 10 Nov 2007 06:20:24 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 30791 invoked by uid 500); 10 Nov 2007 06:20:24 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 30780 invoked by uid 99); 10 Nov 2007 06:20:24 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 09 Nov 2007 22:20:24 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 10 Nov 2007 06:21:14 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 7EBBB1A9832; Fri, 9 Nov 2007 22:20:12 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r593738 - /geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java Date: Sat, 10 Nov 2007 06:20:12 -0000 To: scm@geronimo.apache.org From: jdillon@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071110062012.7EBBB1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jdillon Date: Fri Nov 9 22:20:11 2007 New Revision: 593738 URL: http://svn.apache.org/viewvc?rev=593738&view=rev Log: Split up into methods Modified: geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java Modified: geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java?rev=593738&r1=593737&r2=593738&view=diff ============================================================================== --- geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java (original) +++ geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java Fri Nov 9 22:20:11 2007 @@ -57,73 +57,71 @@ private Renderer renderer = new Renderer(); protected Object doExecute() throws Exception { - assert commandRegistry != null; - assert layoutManager != null; + io.out.println(); if (command == null) { - io.out.println(); - io.out.print(branding.getAbout()); - io.out.println(); - - io.out.println("Available commands:"); - - Collection commands = commandRegistry.commands(); - - // Figure out the maximum length of a command name - int maxNameLen = 0; - for (Command desc : commands) { - if (desc.getId().length() > maxNameLen) { - maxNameLen = desc.getId().length(); - } - } + displayCommands(); + } + else { + displayCommandHelp(command); + } - // - // TODO: Need to ask the LayoutManager... - // - - for (Command d : commands) { - // Hide commands if they don't have descriptions - String name = d.getId(); - name = StringUtils.rightPad(name, maxNameLen); + io.out.println(); - io.out.print(" "); - io.out.print(renderer.render(Renderer.encode(name, Code.BOLD))); + return SUCCESS; + } - String desc = d.getDescription(); + private void displayCommands() throws Exception { + io.out.print(branding.getAbout()); + io.out.println(); - if (desc != null) { - io.out.print(" "); - io.out.println(desc); - } - else { - io.out.println(); - } - } - } - else { - Command cmd = commandRegistry.lookup(command); - if (cmd == null) { - io.out.println("Command " + Renderer.encode(command, Code.BOLD) + " not found."); - io.out.println("Try " + Renderer.encode("help", Code.BOLD) + " for a list of available commands."); - } - else { - io.out.println("Command " + Renderer.encode(command, Code.BOLD)); - io.out.println(" " + cmd.getDescription()); + io.out.println("Available commands:"); + + Collection commands = commandRegistry.commands(); + + // Figure out the maximum length of a command name + int maxNameLen = 0; + for (Command desc : commands) { + if (desc.getId().length() > maxNameLen) { + maxNameLen = desc.getId().length(); } } // - // TODO: Need to figure out a simple way to access i18n text for the command's help + // TODO: Need to ask the LayoutManager... // - - /* - io.out.println(); - io.out.println("For help on a specific command type:"); - io.out.println(" help "); - */ - io.out.println(); + for (Command d : commands) { + // Hide commands if they don't have descriptions + String name = d.getId(); + name = StringUtils.rightPad(name, maxNameLen); - return SUCCESS; + io.out.print(" "); + io.out.print(renderer.render(Renderer.encode(name, Code.BOLD))); + + String desc = d.getDescription(); + + if (desc != null) { + io.out.print(" "); + io.out.println(desc); + } + else { + io.out.println(); + } + } + } + private void displayCommandHelp(final String path) throws Exception { + assert path != null; + + Command cmd = commandRegistry.lookup(path); + + if (cmd == null) { + io.out.println("Command " + Renderer.encode(path, Code.BOLD) + " not found."); + io.out.println("Try " + Renderer.encode("help", Code.BOLD) + " for a list of available commands."); + } + else { + io.out.println("Command " + Renderer.encode(path, Code.BOLD)); + io.out.println(" " + cmd.getDescription()); + } } }