Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 74556 invoked from network); 23 Jun 2006 23:18:29 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 23 Jun 2006 23:18:29 -0000 Received: (qmail 31192 invoked by uid 500); 23 Jun 2006 23:18:28 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 31155 invoked by uid 500); 23 Jun 2006 23:18:28 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 31142 invoked by uid 99); 23 Jun 2006 23:18:28 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 23 Jun 2006 16:18:28 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 23 Jun 2006 16:18:26 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 8A8171A983A; Fri, 23 Jun 2006 16:18:06 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: scm@geronimo.apache.org From: jdillon@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060623231806.8A8171A983A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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() + " [ ...]"; + } + 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] [ ...]", - "", - 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() + " [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] [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() + "