geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r416833 - in /geronimo/sandbox/gshell/trunk: gshell-api/src/main/java/org/apache/geronimo/gshell/command/ gshell-commands/gshell-scripting-commands/src/main/java/org/apache/geronimo/gshell/commands/scripting/ gshell-commands/gshell-standard...
Date Fri, 23 Jun 2006 23:18:04 GMT
Author: jdillon
Date: Fri Jun 23 16:18:03 2006
New Revision: 416833

URL: http://svn.apache.org/viewvc?rev=416833&view=rev
Log:
Moved common code to CommandSupport

Modified:
    geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
    geronimo/sandbox/gshell/trunk/gshell-commands/gshell-scripting-commands/src/main/java/org/apache/geronimo/gshell/commands/scripting/ScriptCommand.java
    geronimo/sandbox/gshell/trunk/gshell-commands/gshell-standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/CatCommand.java
    geronimo/sandbox/gshell/trunk/gshell-commands/gshell-standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/EchoCommand.java
    geronimo/sandbox/gshell/trunk/gshell-commands/gshell-standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/JavaCommand.java
    geronimo/sandbox/gshell/trunk/gshell-commands/gshell-standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/SleepCommand.java
    geronimo/sandbox/gshell/trunk/gshell-commands/gshell-vfs-commands/src/main/java/org/apache/geronimo/gshell/commands/vfs/CopyCommand.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/ExitCommand.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/HelpCommand.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/SetCommand.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/UnsetCommand.java
    geronimo/sandbox/gshell/trunk/gshell-server/gshell-server-core/src/main/java/org/apache/geronimo/gshell/server/ServerCommand.java

Modified: geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java?rev=416833&r1=416832&r2=416833&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
Fri Jun 23 16:18:03 2006
@@ -19,6 +19,9 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.commons.lang.NullArgumentException;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.HelpFormatter;
 import org.apache.geronimo.gshell.console.IO;
 import org.apache.geronimo.gshell.util.Arguments;
 import org.apache.geronimo.gshell.ExitNotification;
@@ -241,5 +244,55 @@
         // Sub-class should override to perform custom execution
 
         return Command.FAILURE;
+    }
+
+    //
+    // CLI Fluff
+    //
+
+    protected Options getOptions() {
+        MessageSource messages = getMessageSource();
+
+        Options options = new Options();
+
+        options.addOption(OptionBuilder.withLongOpt("help")
+            .withDescription(messages.getMessage("cli.option.help"))
+            .create('h'));
+
+        return options;
+    }
+
+    protected String getUsage() {
+        return "[options]";
+    }
+
+    protected void displayHelp(final Options options) {
+        MessageSource messages = getMessageSource();
+        IO io = getIO();
+
+        io.out.print(getName());
+        io.out.print(" -- ");
+        io.out.println(messages.getMessage("cli.usage.description"));
+        io.out.println();
+
+        HelpFormatter formatter = new HelpFormatter();
+        formatter.printHelp(
+            io.out,
+            80, // width (FIXME: Should pull from gshell.columns variable)
+            getName() + " " + getUsage(),
+            "",
+            options,
+            4, // left pad
+            4, // desc pad
+            "",
+            false); // auto usage
+
+        io.out.println();
+
+        String footer = messages.getMessage("cli.usage.footer");
+        if (footer.trim().length() != 0) {
+            io.out.println(footer);
+            io.out.println();
+        }
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-commands/gshell-scripting-commands/src/main/java/org/apache/geronimo/gshell/commands/scripting/ScriptCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-commands/gshell-scripting-commands/src/main/java/org/apache/geronimo/gshell/commands/scripting/ScriptCommand.java?rev=416833&r1=416832&r2=416833&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-commands/gshell-scripting-commands/src/main/java/org/apache/geronimo/gshell/commands/scripting/ScriptCommand.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-commands/gshell-scripting-commands/src/main/java/org/apache/geronimo/gshell/commands/scripting/ScriptCommand.java
Fri Jun 23 16:18:03 2006
@@ -21,7 +21,6 @@
 import org.apache.commons.cli.OptionBuilder;
 import org.apache.commons.cli.PosixParser;
 import org.apache.commons.cli.Options;
-import org.apache.commons.cli.HelpFormatter;
 
 import org.apache.geronimo.gshell.command.Command;
 import org.apache.geronimo.gshell.command.CommandSupport;
@@ -50,22 +49,10 @@
         super("script");
     }
 
-    protected int doExecute(final String[] args) throws Exception {
-        assert args != null;
-
+    protected Options getOptions() {
         MessageSource messages = getMessageSource();
 
-        //
-        // TODO: Optimize, move common code to CommandSupport
-        //
-
-        IO io = getIO();
-
-        Options options = new Options();
-
-        options.addOption(OptionBuilder.withLongOpt("help")
-            .withDescription(messages.getMessage("cli.option.help"))
-            .create('h'));
+        Options options = super.getOptions();
 
         options.addOption(OptionBuilder.withLongOpt("language")
             .withDescription(messages.getMessage("cli.option.language"))
@@ -81,28 +68,23 @@
             .withDescription(messages.getMessage("cli.option.interactive"))
             .create('i'));
 
+        return options;
+    }
+
+    protected int doExecute(final String[] args) throws Exception {
+        assert args != null;
+
+        MessageSource messages = getMessageSource();
+
+        IO io = getIO();
+
+        Options options = getOptions();
+
         CommandLineParser parser = new PosixParser();
         CommandLine line = parser.parse(options, args);
 
         if (line.hasOption('h')) {
-            io.out.print(getName());
-            io.out.print(" -- ");
-            io.out.println(messages.getMessage("cli.usage.description"));
-            io.out.println();
-
-            HelpFormatter formatter = new HelpFormatter();
-            formatter.printHelp(
-                io.out,
-                80, // width (FIXME: Should pull from gshell.columns variable)
-                getName() + " [options]",
-                "",
-                options,
-                4, // left pad
-                4, // desc pad
-                "",
-                false); // auto usage
-
-            io.out.println();
+            displayHelp(options);
 
             return Command.SUCCESS;
         }

Modified: geronimo/sandbox/gshell/trunk/gshell-commands/gshell-standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/CatCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-commands/gshell-standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/CatCommand.java?rev=416833&r1=416832&r2=416833&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-commands/gshell-standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/CatCommand.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-commands/gshell-standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/CatCommand.java
Fri Jun 23 16:18:03 2006
@@ -18,7 +18,6 @@
 
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.HelpFormatter;
 import org.apache.commons.cli.OptionBuilder;
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.PosixParser;
@@ -50,26 +49,30 @@
         super("cat");
     }
 
+    protected Options getOptions() {
+        MessageSource messages = getMessageSource();
+
+        Options options = super.getOptions();
+
+        options.addOption(OptionBuilder
+            .withDescription(messages.getMessage("cli.option.n"))
+            .create('n'));
+
+        return options;
+    }
+
+    protected String getUsage() {
+        return super.getUsage() + " [<file|url> ...]";
+    }
+
     protected int doExecute(final String[] args) throws Exception {
         assert args != null;
 
         MessageSource messages = getMessageSource();
 
-        //
-        // TODO: Optimize, move common code to CommandSupport
-        //
-
         IO io = getIO();
 
-        Options options = new Options();
-
-        options.addOption(OptionBuilder.withLongOpt("help")
-            .withDescription(messages.getMessage("cli.option.help"))
-            .create('h'));
-
-        options.addOption(OptionBuilder
-            .withDescription(messages.getMessage("cli.option.n"))
-            .create('n'));
+        Options options = getOptions();
 
         CommandLineParser parser = new PosixParser();
         CommandLine line = parser.parse(options, args);
@@ -77,24 +80,7 @@
         String[] _args = line.getArgs();
 
         if (line.hasOption('h')) {
-            io.out.print(getName());
-            io.out.print(" -- ");
-            io.out.println(messages.getMessage("cli.usage.description"));
-            io.out.println();
-
-            HelpFormatter formatter = new HelpFormatter();
-            formatter.printHelp(
-                io.out,
-                80, // width (FIXME: Should pull from gshell.columns variable)
-                getName() + " [options] [<file|url> ...]",
-                "",
-                options,
-                4, // left pad
-                4, // desc pad
-                "",
-                false); // auto usage
-
-            io.out.println();
+            displayHelp(options);
 
             return Command.SUCCESS;
         }

Modified: geronimo/sandbox/gshell/trunk/gshell-commands/gshell-standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/EchoCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-commands/gshell-standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/EchoCommand.java?rev=416833&r1=416832&r2=416833&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-commands/gshell-standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/EchoCommand.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-commands/gshell-standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/EchoCommand.java
Fri Jun 23 16:18:03 2006
@@ -18,7 +18,6 @@
 
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.HelpFormatter;
 import org.apache.commons.cli.OptionBuilder;
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.PosixParser;
@@ -40,52 +39,35 @@
     public EchoCommand() {
         super("echo");
     }
-    
-    protected int doExecute(final String[] args) throws Exception {
-        assert args != null;
 
+    protected Options getOptions() {
         MessageSource messages = getMessageSource();
 
-        //
-        // TODO: Optimize, move common code to CommandSupport
-        //
-        
-        IO io = getIO();
-        
-        Options options = new Options();
+        Options options = super.getOptions();
 
-        options.addOption(OptionBuilder.withLongOpt("help")
-            .withDescription(messages.getMessage("cli.option.help"))
-            .create('h'));
-        
         options.addOption(OptionBuilder
             .withDescription(messages.getMessage("cli.option.n"))
             .create('n'));
+
+        return options;
+    }
+
+    protected int doExecute(final String[] args) throws Exception {
+        assert args != null;
+
+        MessageSource messages = getMessageSource();
+
+        IO io = getIO();
         
+        Options options = getOptions();
+
         CommandLineParser parser = new PosixParser();
         CommandLine line = parser.parse(options, args);
 
         String[] _args = line.getArgs();
         
         if (line.hasOption('h')) {
-            io.out.print(getName());
-            io.out.print(" -- ");
-            io.out.println(messages.getMessage("cli.usage.description"));
-            io.out.println();
-
-            HelpFormatter formatter = new HelpFormatter();
-            formatter.printHelp(
-                io.out,
-                80, // width (FIXME: Should pull from gshell.columns variable)
-                getName() + " [options] [string ...]",
-                "",
-                options,
-                4, // left pad
-                4, // desc pad
-                "",
-                false); // auto usage
-            
-            io.out.println();
+            displayHelp(options);
             
             return Command.SUCCESS;
         }

Modified: geronimo/sandbox/gshell/trunk/gshell-commands/gshell-standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/JavaCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-commands/gshell-standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/JavaCommand.java?rev=416833&r1=416832&r2=416833&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-commands/gshell-standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/JavaCommand.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-commands/gshell-standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/JavaCommand.java
Fri Jun 23 16:18:03 2006
@@ -18,7 +18,6 @@
 
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.HelpFormatter;
 import org.apache.commons.cli.OptionBuilder;
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.PosixParser;
@@ -49,28 +48,32 @@
         super("java");
     }
 
-    protected int doExecute(final String[] args) throws Exception {
-        assert args != null;
-
+    protected Options getOptions() {
         MessageSource messages = getMessageSource();
 
-        //
-        // TODO: Optimize, move common code to CommandSupport
-        //
-
-        IO io = getIO();
-
-        Options options = new Options();
-
-        options.addOption(OptionBuilder.withLongOpt("help")
-            .withDescription(messages.getMessage("cli.option.help"))
-            .create('h'));
+        Options options = super.getOptions();
 
         options.addOption(OptionBuilder.withLongOpt("method")
             .withDescription(messages.getMessage("cli.option.method"))
             .withArgName("method")
             .create('M'));
 
+        return options;
+    }
+
+    protected String getUsage() {
+        return super.getUsage() + " <classname> [arguments]";
+    }
+
+    protected int doExecute(final String[] args) throws Exception {
+        assert args != null;
+
+        MessageSource messages = getMessageSource();
+
+        IO io = getIO();
+
+        Options options = getOptions();
+
         CommandLineParser parser = new PosixParser();
         CommandLine line = parser.parse(options, args);
 
@@ -83,24 +86,7 @@
         }
 
         if (usage || line.hasOption('h')) {
-            io.out.print(getName());
-            io.out.print(" -- ");
-            io.out.println(messages.getMessage("cli.usage.description"));
-            io.out.println();
-
-            HelpFormatter formatter = new HelpFormatter();
-            formatter.printHelp(
-                io.out,
-                80, // width (FIXME: Should pull from gshell.columns variable)
-                getName() + " [options] <classname> [arguments]",
-                "",
-                options,
-                4, // left pad
-                4, // desc pad
-                "",
-                false); // auto usage
-
-            io.out.println();
+            displayHelp(options);
 
             return Command.SUCCESS;
         }

Modified: geronimo/sandbox/gshell/trunk/gshell-commands/gshell-standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/SleepCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-commands/gshell-standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/SleepCommand.java?rev=416833&r1=416832&r2=416833&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-commands/gshell-standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/SleepCommand.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-commands/gshell-standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/SleepCommand.java
Fri Jun 23 16:18:03 2006
@@ -18,8 +18,6 @@
 
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.HelpFormatter;
-import org.apache.commons.cli.OptionBuilder;
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.PosixParser;
 import org.apache.geronimo.gshell.command.Command;
@@ -39,22 +37,18 @@
         super("sleep");
     }
 
+    protected String getUsage() {
+        return super.getUsage() + " <time>";
+    }
+
     protected int doExecute(String[] args) throws Exception {
         assert args != null;
 
         MessageSource messages = getMessageSource();
 
-        //
-        // TODO: Optimize, move common code to CommandSupport
-        //
-
         IO io = getIO();
 
-        Options options = new Options();
-
-        options.addOption(OptionBuilder.withLongOpt("help")
-            .withDescription(messages.getMessage("cli.option.help"))
-            .create('h'));
+        Options options = getOptions();
 
         CommandLineParser parser = new PosixParser();
         CommandLine line = parser.parse(options, args);
@@ -71,24 +65,7 @@
         }
 
         if (usage || line.hasOption('h')) {
-            io.out.print(getName());
-            io.out.print(" -- ");
-            io.out.println(messages.getMessage("cli.usage.description"));
-            io.out.println();
-
-            HelpFormatter formatter = new HelpFormatter();
-            formatter.printHelp(
-                io.out,
-                80, // width (FIXME: Should pull from gshell.columns variable)
-                getName() + " [options] <time>",
-                "",
-                options,
-                4, // left pad
-                4, // desc pad
-                "",
-                false); // auto usage
-
-            io.out.println();
+            displayHelp(options);
 
             return Command.SUCCESS;
         }

Modified: geronimo/sandbox/gshell/trunk/gshell-commands/gshell-vfs-commands/src/main/java/org/apache/geronimo/gshell/commands/vfs/CopyCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-commands/gshell-vfs-commands/src/main/java/org/apache/geronimo/gshell/commands/vfs/CopyCommand.java?rev=416833&r1=416832&r2=416833&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-commands/gshell-vfs-commands/src/main/java/org/apache/geronimo/gshell/commands/vfs/CopyCommand.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-commands/gshell-vfs-commands/src/main/java/org/apache/geronimo/gshell/commands/vfs/CopyCommand.java
Fri Jun 23 16:18:03 2006
@@ -21,17 +21,15 @@
 import org.apache.geronimo.gshell.console.IO;
 
 import org.apache.commons.cli.Options;
-import org.apache.commons.cli.OptionBuilder;
 import org.apache.commons.cli.CommandLineParser;
 import org.apache.commons.cli.PosixParser;
 import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.HelpFormatter;
 import org.apache.commons.vfs.FileObject;
 import org.apache.commons.vfs.FileSystemManager;
 import org.apache.commons.vfs.FileUtil;
 
 /**
- * ???
+ * Copy files.
  *
  * @version $Id$
  */
@@ -42,22 +40,18 @@
         super("copy");
     }
 
+    protected String getUsage() {
+        return super.getUsage() + " <source> <target>";
+    }
+
     protected int doExecute(String[] args) throws Exception {
         assert args != null;
 
         MessageSource messages = getMessageSource();
 
-        //
-        // TODO: Optimize, move common code to CommandSupport
-        //
-
         IO io = getIO();
 
-        Options options = new Options();
-
-        options.addOption(OptionBuilder.withLongOpt("help")
-            .withDescription(messages.getMessage("cli.option.help"))
-            .create('h'));
+        Options options = getOptions();
 
         CommandLineParser parser = new PosixParser();
         CommandLine line = parser.parse(options, args);
@@ -72,26 +66,7 @@
         }
 
         if (usage || line.hasOption('h')) {
-            io.out.print(getName());
-            io.out.print(" -- ");
-            io.out.println(messages.getMessage("cli.usage.description"));
-            io.out.println();
-
-            HelpFormatter formatter = new HelpFormatter();
-            formatter.printHelp(
-                io.out,
-                80, // width (FIXME: Should pull from gshell.columns variable)
-                getName() + " [options] <source> <target>",
-                "",
-                options,
-                4, // left pad
-                4, // desc pad
-                "",
-                false); // auto usage
-
-            // io.out.println();
-            // io.out.println(messages.getMessage("cli.usage.footer"));
-            io.out.println();
+            displayHelp(options);
 
             return Command.SUCCESS;
         }

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/ExitCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/ExitCommand.java?rev=416833&r1=416832&r2=416833&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/ExitCommand.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/ExitCommand.java
Fri Jun 23 16:18:03 2006
@@ -18,8 +18,6 @@
 
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.HelpFormatter;
-import org.apache.commons.cli.OptionBuilder;
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.PosixParser;
 import org.apache.geronimo.gshell.command.Command;
@@ -41,22 +39,18 @@
         super("exit");
     }
 
+    protected String getUsage() {
+        return super.getUsage() + " [code]";
+    }
+
     protected int doExecute(String[] args) throws Exception {
         assert args != null;
 
         MessageSource messages = getMessageSource();
 
-        //
-        // TODO: Optimize, move common code to CommandSupport
-        //
-
         IO io = getIO();
 
-        Options options = new Options();
-
-        options.addOption(OptionBuilder.withLongOpt("help")
-            .withDescription(messages.getMessage("cli.option.help"))
-            .create('h'));
+        Options options = getOptions();
 
         CommandLineParser parser = new PosixParser();
         CommandLine line = parser.parse(options, args);
@@ -75,24 +69,7 @@
         }
 
         if (usage || line.hasOption('h')) {
-            io.out.print(getName());
-            io.out.print(" -- ");
-            io.out.println(messages.getMessage("cli.usage.description"));
-            io.out.println();
-            
-            HelpFormatter formatter = new HelpFormatter();
-            formatter.printHelp(
-                io.out,
-                80, // width (FIXME: Should pull from gshell.columns variable)
-                getName() + " [options] [code]",
-                "",
-                options,
-                4, // left pad
-                4, // desc pad
-                "",
-                false); // auto usage
-
-            io.out.println();
+            displayHelp(options);
 
             return Command.SUCCESS;
         }

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/HelpCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/HelpCommand.java?rev=416833&r1=416832&r2=416833&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/HelpCommand.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/HelpCommand.java
Fri Jun 23 16:18:03 2006
@@ -18,8 +18,6 @@
 
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.HelpFormatter;
-import org.apache.commons.cli.OptionBuilder;
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.PosixParser;
 
@@ -66,22 +64,18 @@
         return commandManager;
     }
 
+    protected String getUsage() {
+        return super.getUsage() + " [topic|command]";
+    }
+
     protected int doExecute(final String[] args) throws Exception {
         assert args != null;
 
         MessageSource messages = getMessageSource();
 
-        //
-        // TODO: Optimize, move common code to CommandSupport
-        //
-
         IO io = getIO();
 
-        Options options = new Options();
-
-        options.addOption(OptionBuilder.withLongOpt("help")
-            .withDescription(messages.getMessage("cli.option.help"))
-            .create('h'));
+        Options options = getOptions();
 
         CommandLineParser parser = new PosixParser();
         CommandLine line = parser.parse(options, args);
@@ -102,27 +96,8 @@
         }
 
         if (usage || line.hasOption('h')) {
-            io.out.print(getName());
-            io.out.print(" -- ");
-            io.out.println(messages.getMessage("cli.usage.description"));
-            io.out.println();
-
-            HelpFormatter formatter = new HelpFormatter();
-            formatter.printHelp(
-                io.out,
-                80, // width (FIXME: Should pull from gshell.columns variable)
-                getName() + " [options] [topic|command]",
-                "",
-                options,
-                4, // left pad
-                4, // desc pad
-                "",
-                false); // auto usage
-
-            io.out.println();
-            io.out.println(messages.getMessage("cli.usage.footer"));
-            io.out.println();
-            
+            displayHelp(options);
+
             return Command.SUCCESS;
         }
 

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/SetCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/SetCommand.java?rev=416833&r1=416832&r2=416833&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/SetCommand.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/SetCommand.java
Fri Jun 23 16:18:03 2006
@@ -18,7 +18,6 @@
 
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.HelpFormatter;
 import org.apache.commons.cli.OptionBuilder;
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.PosixParser;
@@ -50,26 +49,30 @@
         PROPERTY
     }
 
+    protected Options getOptions() {
+        MessageSource messages = getMessageSource();
+
+        Options options = super.getOptions();
+
+        options.addOption(OptionBuilder.withLongOpt("property")
+            .withDescription(messages.getMessage("cli.option.property"))
+            .create('p'));
+
+        return options;
+    }
+
+    protected String getUsage() {
+        return super.getUsage() + " (<name[=value>])*";
+    }
+
     protected int doExecute(String[] args) throws Exception {
         assert args != null;
 
         MessageSource messages = getMessageSource();
 
-        //
-        // TODO: Optimize, move common code to CommandSupport
-        //
-
         IO io = getIO();
 
-        Options options = new Options();
-
-        options.addOption(OptionBuilder.withLongOpt("help")
-            .withDescription(messages.getMessage("cli.option.help"))
-            .create('h'));
-
-        options.addOption(OptionBuilder.withLongOpt("property")
-            .withDescription(messages.getMessage("cli.option.property"))
-            .create('p'));
+        Options options = getOptions();
 
         //
         // TODO: Add support to set immutable
@@ -83,26 +86,7 @@
         CommandLine line = parser.parse(options, args);
 
         if (line.hasOption('h')) {
-            io.out.print(getName());
-            io.out.print(" -- ");
-            io.out.println(messages.getMessage("cli.usage.description"));
-            io.out.println();
-
-            HelpFormatter formatter = new HelpFormatter();
-            formatter.printHelp(
-                io.out,
-                80, // width (FIXME: Should pull from gshell.columns variable)
-                getName() + " [options] (<name[=value>])*",
-                "",
-                options,
-                4, // left pad
-                4, // desc pad
-                "",
-                false); // auto usage
-
-            io.out.println();
-            io.out.println(messages.getMessage("cli.usage.footer"));
-            io.out.println();
+            displayHelp(options);
 
             return Command.SUCCESS;
         }

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/UnsetCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/UnsetCommand.java?rev=416833&r1=416832&r2=416833&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/UnsetCommand.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/UnsetCommand.java
Fri Jun 23 16:18:03 2006
@@ -18,7 +18,6 @@
 
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.HelpFormatter;
 import org.apache.commons.cli.OptionBuilder;
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.PosixParser;
@@ -47,26 +46,30 @@
         PROPERTY
     }
 
+    protected Options getOptions() {
+        MessageSource messages = getMessageSource();
+
+        Options options = super.getOptions();
+
+        options.addOption(OptionBuilder.withLongOpt("property")
+            .withDescription(messages.getMessage("cli.option.property"))
+            .create('p'));
+
+        return options;
+    }
+
+    protected String getUsage() {
+        return super.getUsage() + " (<name>)+";
+    }
+
     protected int doExecute(String[] args) throws Exception {
         assert args != null;
 
         MessageSource messages = getMessageSource();
 
-        //
-        // TODO: Optimize, move common code to CommandSupport
-        //
-
         IO io = getIO();
 
-        Options options = new Options();
-
-        options.addOption(OptionBuilder.withLongOpt("help")
-            .withDescription(messages.getMessage("cli.option.help"))
-            .create('h'));
-
-        options.addOption(OptionBuilder.withLongOpt("property")
-            .withDescription(messages.getMessage("cli.option.property"))
-            .create('p'));
+        Options options = getOptions();
 
         //
         // TODO: Add support to unset in parent (parent) scope
@@ -83,24 +86,7 @@
         }
 
         if (usage || line.hasOption('h')) {
-            io.out.print(getName());
-            io.out.print(" -- ");
-            io.out.println(messages.getMessage("cli.usage.description"));
-            io.out.println();
-
-            HelpFormatter formatter = new HelpFormatter();
-            formatter.printHelp(
-                io.out,
-                80, // width (FIXME: Should pull from gshell.columns variable)
-                getName() + " [options] (<name>)+",
-                "",
-                options,
-                4, // left pad
-                4, // desc pad
-                "",
-                false); // auto usage
-
-            io.out.println();
+            displayHelp(options);
 
             return Command.SUCCESS;
         }

Modified: geronimo/sandbox/gshell/trunk/gshell-server/gshell-server-core/src/main/java/org/apache/geronimo/gshell/server/ServerCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-server/gshell-server-core/src/main/java/org/apache/geronimo/gshell/server/ServerCommand.java?rev=416833&r1=416832&r2=416833&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-server/gshell-server-core/src/main/java/org/apache/geronimo/gshell/server/ServerCommand.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-server/gshell-server-core/src/main/java/org/apache/geronimo/gshell/server/ServerCommand.java
Fri Jun 23 16:18:03 2006
@@ -18,7 +18,6 @@
 
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.HelpFormatter;
 import org.apache.commons.cli.OptionBuilder;
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.PosixParser;
@@ -44,50 +43,33 @@
         super("server");
     }
 
-    protected int doExecute(final String[] args) throws Exception {
-        assert args != null;
-
+    protected Options getOptions() {
         MessageSource messages = getMessageSource();
 
-        //
-        // TODO: Optimize, move common code to CommandSupport
-        //
-
-        IO io = getIO();
-
-        Options options = new Options();
-
-        options.addOption(OptionBuilder.withLongOpt("help")
-            .withDescription(messages.getMessage("cli.option.help"))
-            .create('h'));
+        Options options = super.getOptions();
 
         options.addOption(OptionBuilder.withLongOpt("port")
             .withDescription(messages.getMessage("cli.option.port"))
             .hasArg()
             .create('p'));
 
+        return options;
+    }
+
+    protected int doExecute(final String[] args) throws Exception {
+        assert args != null;
+
+        MessageSource messages = getMessageSource();
+
+        IO io = getIO();
+
+        Options options = getOptions();
+
         CommandLineParser parser = new PosixParser();
         CommandLine line = parser.parse(options, args);
 
         if (line.hasOption('h')) {
-            io.out.print(getName());
-            io.out.print(" -- ");
-            io.out.println(messages.getMessage("cli.usage.description"));
-            io.out.println();
-
-            HelpFormatter formatter = new HelpFormatter();
-            formatter.printHelp(
-                io.out,
-                80, // width (FIXME: Should pull from gshell.columns variable)
-                getName() + " [options]",
-                "",
-                options,
-                4, // left pad
-                4, // desc pad
-                "",
-                false); // auto usage
-
-            io.out.println();
+            displayHelp(options);
 
             return Command.SUCCESS;
         }



Mime
View raw message