geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r665794 - in /geronimo/gshell/trunk: gshell-commands/gshell-command-support/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java gshell-core/src/main/java/org/apache/geronimo/gshell/container/DefaultCommandContainer.java
Date Mon, 09 Jun 2008 17:29:52 GMT
Author: jdillon
Date: Mon Jun  9 10:29:52 2008
New Revision: 665794

URL: http://svn.apache.org/viewvc?rev=665794&view=rev
Log:
Move the CLP processing from CommandSupport to DefaultCommandContainer

Modified:
    geronimo/gshell/trunk/gshell-commands/gshell-command-support/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
    geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/container/DefaultCommandContainer.java

Modified: geronimo/gshell/trunk/gshell-commands/gshell-command-support/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-command-support/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java?rev=665794&r1=665793&r2=665794&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-command-support/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
(original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-command-support/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
Mon Jun  9 10:29:52 2008
@@ -19,11 +19,7 @@
 
 package org.apache.geronimo.gshell.command;
 
-import org.apache.geronimo.gshell.clp.CommandLineProcessor;
-import org.apache.geronimo.gshell.clp.Option;
-import org.apache.geronimo.gshell.clp.Printer;
 import org.apache.geronimo.gshell.command.annotation.CommandComponent;
-import org.apache.geronimo.gshell.common.Arguments;
 import org.apache.geronimo.gshell.io.IO;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -43,9 +39,6 @@
     protected IO io;
 
     protected Variables variables;
-    
-    @Option(name="-h", aliases={"--help"}, description="Display this help message", requireOverride=true)
-    private boolean displayHelp;
 
     @Deprecated
     public String getId() {
@@ -82,48 +75,9 @@
         assert args != null;
 
         init(context);
-
-        log.info("Executing w/args: [{}]", Arguments.asString(args));
-
-        //
-        // HACK: Need to move all of this up to the container, exposing a help support component
-        //
-
-        CommandLineProcessor clp = new CommandLineProcessor(this);
-        // clp.process(Arguments.toStringArray(args));
-
-        // Handle --help/-h automatically for the command
-        if (displayHelp) {
-            //
-            // TODO: Make a special PrinterHandler to abstract this muck from having to process
it by hand
-            //
-            
-            displayHelp(context, clp);
-            
-            return SUCCESS;
-        }
-
+        
         return doExecute();
     }
 
     protected abstract Object doExecute() throws Exception;
-
-    protected void displayHelp(final CommandContext context, final CommandLineProcessor clp)
{
-        assert context != null;
-        assert clp != null;
-
-        // Use the alias if we have one, else use the command name
-        String name = context.getInfo().getAlias();
-        if (name == null) {
-            name = context.getInfo().getName();
-        }
-
-        //
-        // FIXME: This is uuuuuggggllyyyy
-        //
-
-        Printer printer = new Printer(clp);
-        printer.printUsage(io.out, name);
-        io.out.println();
-    }
 }

Modified: geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/container/DefaultCommandContainer.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/container/DefaultCommandContainer.java?rev=665794&r1=665793&r2=665794&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/container/DefaultCommandContainer.java
(original)
+++ geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/container/DefaultCommandContainer.java
Mon Jun  9 10:29:52 2008
@@ -22,9 +22,13 @@
 import org.apache.geronimo.gshell.command.CommandContainer;
 import org.apache.geronimo.gshell.command.CommandContext;
 import org.apache.geronimo.gshell.command.Executable;
+import org.apache.geronimo.gshell.command.Command;
 import org.apache.geronimo.gshell.plexus.GShellPlexusContainer;
 import org.apache.geronimo.gshell.common.Arguments;
 import org.apache.geronimo.gshell.clp.CommandLineProcessor;
+import org.apache.geronimo.gshell.clp.Option;
+import org.apache.geronimo.gshell.clp.Printer;
+import org.apache.geronimo.gshell.io.IO;
 import org.codehaus.plexus.PlexusConstants;
 import org.codehaus.plexus.component.annotations.Component;
 import org.codehaus.plexus.component.annotations.Configuration;
@@ -98,17 +102,48 @@
         // TODO: Bind context, io and variables
 
         // Process command line options/arguments
-        CommandLineProcessor clp = new CommandLineProcessor(executable);
-        clp.process(Arguments.toStringArray(args));
+        CommandLineProcessor clp = new CommandLineProcessor();
+        clp.addBean(executable);
+
+        // Attach some help context
+        HelpSupport help = new HelpSupport();
+        clp.addBean(help);
 
-        //
-        // TODO: Need to augment the clp to allow it to handle a set of objects, so we can
use a nested object here to inject --help support automatically
-        //
+        // Process the arguments
+        clp.process(Arguments.toStringArray(args));
 
+        // Display help if option detected
+        if (help.displayHelp) {
+            help.displayHelp(context, clp);
+            return Command.SUCCESS;
+        }
+        
         Object result = executable.execute(context, args);
 
         log.trace("Result: {}", result);
 
         return result;
     }
+
+    private static class HelpSupport
+    {
+        @Option(name="-h", aliases={"--help"}, description="Display this help message", requireOverride=true)
+        public boolean displayHelp;
+
+        protected void displayHelp(final CommandContext context, final CommandLineProcessor
clp) {
+            assert context != null;
+            assert clp != null;
+
+            // Use the alias if we have one, else use the command name
+            String name = context.getInfo().getAlias();
+            if (name == null) {
+                name = context.getInfo().getName();
+            }
+
+            IO io = context.getIO();
+            Printer printer = new Printer(clp);
+            printer.printUsage(io.out, name);
+            io.out.println();
+        }
+    }
 }
\ No newline at end of file



Mime
View raw message