Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 7280 invoked from network); 14 Sep 2008 09:53:42 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 14 Sep 2008 09:53:42 -0000 Received: (qmail 55999 invoked by uid 500); 14 Sep 2008 09:53:39 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 55931 invoked by uid 500); 14 Sep 2008 09:53:38 -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 55922 invoked by uid 99); 14 Sep 2008 09:53:38 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 14 Sep 2008 02:53:38 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 14 Sep 2008 09:52:40 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 4286C23889FD; Sun, 14 Sep 2008 02:53:13 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r695171 - in /geronimo/gshell/trunk: gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/ gshell-commands/gshell-builtins/src/main/resources/org/apache/geronimo/gshell/commands/builtins/ gshell-support... Date: Sun, 14 Sep 2008 09:53:11 -0000 To: scm@geronimo.apache.org From: jdillon@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080914095313.4286C23889FD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jdillon Date: Sun Sep 14 02:53:08 2008 New Revision: 695171 URL: http://svn.apache.org/viewvc?rev=695171&view=rev Log: Hook up i18n support for clp printing Modified: geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/EchoCommand.java geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/org/apache/geronimo/gshell/commands/builtins/EchoCommand.properties geronimo/gshell/trunk/gshell-support/gshell-clp/pom.xml geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/CommandLineProcessor.java geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Printer.java geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandDocumenterImpl.java Modified: geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/EchoCommand.java URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/EchoCommand.java?rev=695171&r1=695170&r2=695171&view=diff ============================================================================== --- geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/EchoCommand.java (original) +++ geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/EchoCommand.java Sun Sep 14 02:53:08 2008 @@ -39,11 +39,11 @@ { private final Logger log = LoggerFactory.getLogger(getClass()); - @Option(name="-n", description="Do not print the trailing newline character") + @Option(name="-n", description="command.option.trailingNewline") private boolean trailingNewline = true; @SuppressWarnings({"MismatchedQueryAndUpdateOfCollection"}) - @Argument(description="Arguments") + @Argument(description="command.argument.args") private List args; public Object execute(final CommandContext context) throws Exception { Modified: geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/org/apache/geronimo/gshell/commands/builtins/EchoCommand.properties URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/org/apache/geronimo/gshell/commands/builtins/EchoCommand.properties?rev=695171&r1=695170&r2=695171&view=diff ============================================================================== --- geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/org/apache/geronimo/gshell/commands/builtins/EchoCommand.properties (original) +++ geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/org/apache/geronimo/gshell/commands/builtins/EchoCommand.properties Sun Sep 14 02:53:08 2008 @@ -25,5 +25,11 @@ command.description=Print arguments to standard output. +command.option.help=Display this help message + +command.option.trailingNewline=Do not print the trailing newline character + +command.argument.args=Arguments + command.manual=\ TODO: echo manual \ No newline at end of file Modified: geronimo/gshell/trunk/gshell-support/gshell-clp/pom.xml URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-clp/pom.xml?rev=695171&r1=695170&r2=695171&view=diff ============================================================================== --- geronimo/gshell/trunk/gshell-support/gshell-clp/pom.xml (original) +++ geronimo/gshell/trunk/gshell-support/gshell-clp/pom.xml Sun Sep 14 02:53:08 2008 @@ -37,4 +37,11 @@ Annotation-based command-line processing support. + + + org.apache.geronimo.gshell.support + gshell-i18n + + + \ No newline at end of file Modified: geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/CommandLineProcessor.java URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/CommandLineProcessor.java?rev=695171&r1=695170&r2=695171&view=diff ============================================================================== --- geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/CommandLineProcessor.java (original) +++ geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/CommandLineProcessor.java Sun Sep 14 02:53:08 2008 @@ -30,6 +30,7 @@ import java.util.Set; import java.util.TreeMap; +import org.apache.geronimo.gshell.i18n.MessageSource; import org.apache.geronimo.gshell.clp.handler.Handler; import org.apache.geronimo.gshell.clp.handler.Handlers; import org.apache.geronimo.gshell.clp.handler.Parameters; @@ -58,7 +59,7 @@ addBean(bean); } - + public List getOptionHandlers() { return Collections.unmodifiableList(optionHandlers); } Modified: geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Printer.java URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Printer.java?rev=695171&r1=695170&r2=695171&view=diff ============================================================================== --- geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Printer.java (original) +++ geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Printer.java Sun Sep 14 02:53:08 2008 @@ -28,6 +28,8 @@ import java.util.ResourceBundle; import org.apache.geronimo.gshell.clp.handler.Handler; +import org.apache.geronimo.gshell.i18n.MessageSource; +import org.apache.geronimo.gshell.i18n.ResourceNotFoundException; /** * Helper to print formatted help and usage text. @@ -38,12 +40,20 @@ { private CommandLineProcessor processor; + private MessageSource messages; + public Printer(final CommandLineProcessor processor) { assert processor != null; this.processor = processor; } + public void setMessageSource(final MessageSource messages) { + assert messages != null; + + this.messages = messages; + } + private String getMetaVariable(final Handler handler, final ResourceBundle bundle) { assert handler != null; @@ -110,6 +120,10 @@ return a.descriptor.toString().compareTo(b.descriptor.toString()); } }); + + // + // TODO: i18n, pull for standard messages, not from command's messages + // if (name != null) { String syntax = "syntax: " + name; @@ -164,6 +178,26 @@ printUsage(writer, null, name); } + /** + * Get the description for the given descriptor, using any configured messages for i18n support. + */ + private String getDescription(final Descriptor descriptor) { + assert descriptor != null; + + String message = descriptor.description(); + + if (message != null && messages != null) { + try { + message = messages.getMessage(message); + } + catch (ResourceNotFoundException e) { + // Just use the code + } + } + + return message; + } + private void printHandler(final PrintWriter out, final Handler handler, final int len, final ResourceBundle bundle) { assert out != null; assert handler != null; @@ -179,7 +213,7 @@ int descriptionWidth = terminalWidth - len - prefixSeperatorWidth; // Only render if their is a discription, else its hidden - String desc = handler.descriptor.description(); + String desc = getDescription(handler.descriptor); if (desc.length() == 0) { return; } @@ -203,7 +237,7 @@ // Render the description splitting it over multipule lines if its longer than column size while (desc != null && desc.length() > 0) { // - // TODO: Should relaly only split on words here... + // FIXME: Only split on words // int i = desc.indexOf('\n'); Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandDocumenterImpl.java URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandDocumenterImpl.java?rev=695171&r1=695170&r2=695171&view=diff ============================================================================== --- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandDocumenterImpl.java (original) +++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandDocumenterImpl.java Sun Sep 14 02:53:08 2008 @@ -45,7 +45,7 @@ public String getName() { if (name == null) { - name = getMessage("command.name"); + name = getContainer().getMessages().getMessage("command.name"); } return name; } @@ -56,7 +56,7 @@ public String getDescription() { if (description == null) { - description = getMessage("command.description"); + description = getContainer().getMessages().getMessage("command.description"); } return description; } @@ -67,7 +67,7 @@ public String getManual() { if (manual == null) { - manual = getMessage("command.manual"); + manual = getContainer().getMessages().getMessage("command.manual"); } return manual; } @@ -76,15 +76,6 @@ this.manual = manual; } - private String getMessage(final String code) { - assert code != null; - - MessageSource messages = getContainer().getMessages(); - assert messages != null; - - return messages.getMessage(code); - } - // CommandDocumenter public void renderUsage(final CommandInfo info, final PrintWriter out) { @@ -94,7 +85,7 @@ log.debug("Rendering command usage"); CommandLineProcessor clp = new CommandLineProcessor(); - + // Attach our helper to inject --help CommandContainerImpl.HelpSupport help = new CommandContainerImpl.HelpSupport(); clp.addBean(help); @@ -107,15 +98,12 @@ String name = getName(); String desc = getDescription(); - // - // TODO: Add some nice ANSI muck - // - // Render the help out.println(desc); out.println(); Printer printer = new Printer(clp); + printer.setMessageSource(getContainer().getMessages()); printer.printUsage(out, name); out.println();