geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
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 GMT
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<Command> 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<Command> 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 <command>");
-        */
 
-        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());
+        }
     }
 }



Mime
View raw message