geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r594368 - in /geronimo/gshell/trunk: gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/ gshell-core/src/main/java/org/apache/geronimo/gshell/
Date Tue, 13 Nov 2007 00:41:36 GMT
Author: jdillon
Date: Mon Nov 12 16:41:34 2007
New Revision: 594368

URL: http://svn.apache.org/viewvc?rev=594368&view=rev
Log:
(GSHELL-55) Added getCommandName(), getCommandId() and getAliasName() to CommandContext

Modified:
    geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/Command.java
    geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandContext.java
    geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
    geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultCommandExecutor.java

Modified: geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/Command.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/Command.java?rev=594368&r1=594367&r2=594368&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/Command.java
(original)
+++ geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/Command.java
Mon Nov 12 16:41:34 2007
@@ -32,17 +32,10 @@
     /** Standard command failure status code. */
     Result FAILURE = Result.FAILURE;
 
-    /**
-     * Command id
-     *
-     * @return
-     */
+    @Deprecated
     String getId();
 
-    /**
-     * Description of the command
-     * @return
-     */
+    @Deprecated
     String getDescription();
 
     /**

Modified: geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandContext.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandContext.java?rev=594368&r1=594367&r2=594368&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandContext.java
(original)
+++ geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandContext.java
Mon Nov 12 16:41:34 2007
@@ -29,4 +29,10 @@
     IO getIO();
 
     Variables getVariables();
+
+    String getCommandId();
+
+    String getCommandName();
+
+    String getAliasName();
 }

Modified: geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java?rev=594368&r1=594367&r2=594368&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
(original)
+++ geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
Mon Nov 12 16:41:34 2007
@@ -46,6 +46,7 @@
     @Option(name="-h", aliases={"--help"}, description="Display this help message", requireOverride=true)
     private boolean displayHelp;
 
+    @Deprecated
     public String getId() {
         CommandComponent cmd = getClass().getAnnotation(CommandComponent.class);
         if (cmd == null) {
@@ -54,6 +55,7 @@
         return cmd.id();
     }
 
+    @Deprecated
     public String getDescription() {
         CommandComponent cmd = getClass().getAnnotation(CommandComponent.class);
         if (cmd == null) {
@@ -91,7 +93,7 @@
             // TODO: Make a special PrinterHandler to abstrat this muck from having to process
it by hand
             //
             
-            displayHelp(clp);
+            displayHelp(context, clp);
             
             return SUCCESS;
         }
@@ -105,14 +107,16 @@
 
     protected abstract Object doExecute() throws Exception;
 
-    protected void displayHelp(final CommandLineProcessor clp) {
+    protected void displayHelp(final CommandContext context, final CommandLineProcessor clp)
{
+        assert context != null;
         assert clp != null;
 
-        //
-        // TODO: Need to ask the LayoutManager what the real name is for our command's ID
-        //
+        String name = context.getAliasName();
+        if (name == null) {
+            name = context.getCommandName();
+        }
 
-        io.out.println(getId());
+        io.out.println(name);
         io.out.println(" -- ");
         io.out.println();
 

Modified: geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultCommandExecutor.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultCommandExecutor.java?rev=594368&r1=594367&r2=594368&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultCommandExecutor.java
(original)
+++ geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultCommandExecutor.java
Mon Nov 12 16:41:34 2007
@@ -125,27 +125,23 @@
         throw new NotFoundException("Unable to get command id for: " + node);
     }
 
-    private Command findCommand(final String path) throws NotFoundException {
-        Node node = layoutManager.findNode(path);
+    public Object execute(final String path, final Object[] args) throws Exception {
+        assert path != null;
+        assert args != null;
+
+        log.info("Executing ({}): [{}]", path, Arguments.asString(args));
+
+        final Node node = layoutManager.findNode(path);
 
-        String id = findCommandId(node);
+        final String id = findCommandId(node);
 
+        final Command command;
         try {
-            return commandRegistry.lookup(id);
+            command = commandRegistry.lookup(id);
         }
         catch (NotRegisteredException e) {
             throw new NotFoundException(e.getMessage());
         }
-    }
-
-    public Object execute(final String path, final Object[] args) throws Exception {
-        assert path != null;
-        assert args != null;
-
-        log.info("Executing ({}): [{}]", path, Arguments.asString(args));
-
-        // Look up the command for the given path
-        Command command = findCommand(path);
 
         // Setup the command context and pass it to the command instance
         CommandContext context = new CommandContext() {
@@ -158,6 +154,26 @@
 
             public Variables getVariables() {
                 return vars;
+            }
+
+            public String getCommandId() {
+                return id;
+            }
+
+            public String getCommandName() {
+                if (node instanceof AliasNode) {
+                    return ((AliasNode)node).getCommand();
+                }
+
+                return node.getName();
+            }
+
+            public String getAliasName() {
+                if (node instanceof AliasNode) {
+                    return ((AliasNode)node).getName();
+                }
+
+                return null;
             }
         };
 



Mime
View raw message