geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
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 GMT
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<String> 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.
     </description>
 
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.geronimo.gshell.support</groupId>
+            <artifactId>gshell-i18n</artifactId>
+        </dependency>
+    </dependencies>
+
 </project>
\ 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<Handler> 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();



Mime
View raw message