geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r593742 - in /geronimo/gshell/trunk: gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java gshell-core/src/main/java/org/apache/geronimo/gshell/layout/model/GroupNode.java
Date Sat, 10 Nov 2007 07:07:28 GMT
Author: jdillon
Date: Fri Nov  9 23:07:27 2007
New Revision: 593742

URL: http://svn.apache.org/viewvc?rev=593742&view=rev
Log:
(GSHELL-44) Add primitive help display including groups

Modified:
    geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java
    geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/model/GroupNode.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=593742&r1=593741&r2=593742&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 23:07:27 2007
@@ -19,8 +19,6 @@
 
 package org.apache.geronimo.gshell.commands.builtins;
 
-import java.util.Collection;
-
 import org.apache.geronimo.gshell.ansi.Code;
 import org.apache.geronimo.gshell.ansi.Renderer;
 import org.apache.geronimo.gshell.branding.Branding;
@@ -30,6 +28,10 @@
 import org.apache.geronimo.gshell.command.annotation.CommandComponent;
 import org.apache.geronimo.gshell.command.annotation.Requirement;
 import org.apache.geronimo.gshell.layout.LayoutManager;
+import org.apache.geronimo.gshell.layout.model.AliasNode;
+import org.apache.geronimo.gshell.layout.model.CommandNode;
+import org.apache.geronimo.gshell.layout.model.GroupNode;
+import org.apache.geronimo.gshell.layout.model.Node;
 import org.apache.geronimo.gshell.registry.CommandRegistry;
 import org.codehaus.plexus.util.StringUtils;
 
@@ -60,56 +62,78 @@
         io.out.println();
 
         if (command == null) {
-            displayCommands();
+            displayAvailableCommands();
         }
         else {
             displayCommandHelp(command);
         }
 
-        io.out.println();
-
         return SUCCESS;
     }
 
-    private void displayCommands() throws Exception {
+    private void displayAvailableCommands() throws Exception {
         io.out.print(branding.getAbout());
         io.out.println();
-
         io.out.println("Available commands:");
 
-        Collection<Command> commands = commandRegistry.commands();
+        GroupNode group = layoutManager.getLayout();
 
-        // 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();
-            }
-        }
+        displayGroupCommands(group);
+    }
+
+    private void displayGroupCommands(final GroupNode group) throws Exception {
+        int maxNameLen = 20; // FIXME: Figure this out dynamically
 
-        //
-        // TODO: Need to ask the LayoutManager...
-        //
+        // First display command/aliases nodes
+        for (Node child : group.nodes()) {
+            if (child instanceof CommandNode) {
+                CommandNode node = (CommandNode) child;
+                String name = StringUtils.rightPad(node.getName(), maxNameLen);
 
-        for (Command d : commands) {
-            // Hide commands if they don't have descriptions
-            String name = d.getId();
-            name = StringUtils.rightPad(name, maxNameLen);
+                io.out.print("  ");
+                io.out.print(renderer.render(Renderer.encode(name, Code.BOLD)));
 
-            io.out.print("  ");
-            io.out.print(renderer.render(Renderer.encode(name, Code.BOLD)));
+                Command command = commandRegistry.lookup(node.getId());
+                String desc = command.getDescription();
 
-            String desc = d.getDescription();
+                if (desc != null) {
+                    io.out.print("  ");
+                    io.out.println(desc);
+                }
+                else {
+                    io.out.println();
+                }
+            }
+            else if (child instanceof AliasNode) {
+                AliasNode node = (AliasNode) child;
+                String name = StringUtils.rightPad(node.getName(), maxNameLen);
 
-            if (desc != null) {
                 io.out.print("  ");
-                io.out.println(desc);
+                io.out.print(renderer.render(Renderer.encode(name, Code.BOLD)));
+                io.out.print("  ");
+
+                io.out.print("Alias to: ");
+                io.out.println(renderer.render(Renderer.encode(node.getCommand(), Code.BOLD)));
             }
-            else {
+        }
+
+        io.out.println();
+
+        // Then groups
+        for (Node child : group.nodes()) {
+            if (child instanceof GroupNode) {
+                GroupNode node = (GroupNode) child;
+
+                io.out.print("  ");
+                io.out.println(renderer.render(Renderer.encode(node.getPath(), Code.BOLD)));
+
+                io.out.println();
+                displayGroupCommands(node);
                 io.out.println();
             }
         }
     }
+
     private void displayCommandHelp(final String path) throws Exception {
         assert path != null;
 
@@ -123,5 +147,7 @@
             io.out.println("Command " + Renderer.encode(path, Code.BOLD));
             io.out.println("   " + cmd.getDescription());
         }
+
+        io.out.println();
     }
 }

Modified: geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/model/GroupNode.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/model/GroupNode.java?rev=593742&r1=593741&r2=593742&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/model/GroupNode.java
(original)
+++ geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/model/GroupNode.java
Fri Nov  9 23:07:27 2007
@@ -24,6 +24,7 @@
 import java.util.Set;
 
 import com.thoughtworks.xstream.annotations.XStreamAlias;
+import org.apache.geronimo.gshell.layout.LayoutManager;
 
 /**
  * A group of nodes.
@@ -38,6 +39,27 @@
 
     public GroupNode(final String name) {
         super(name);
+    }
+
+    public String getPath() {
+        StringBuffer buff = new StringBuffer();
+        Node node = this;
+
+        while (node != null) {
+            buff.insert(0, node.getName());
+
+            node = node.getParent();
+
+            if (node != null) {
+                buff.insert(0, LayoutManager.PATH_SEPARATOR);
+            }
+
+            if (node instanceof Layout) {
+                break;
+            }
+        }
+
+        return buff.toString();
     }
 
     public void add(final Node child) {



Mime
View raw message