geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r698998 - in /geronimo/gshell/trunk: gshell-api/src/main/java/org/apache/geronimo/gshell/command/ gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/ gshell-wisdom/gshell-wisdom-core/src/main/java/org...
Date Thu, 25 Sep 2008 15:15:04 GMT
Author: jdillon
Date: Thu Sep 25 08:15:03 2008
New Revision: 698998

URL: http://svn.apache.org/viewvc?rev=698998&view=rev
Log:
Use Collection for registrations API
Split up HelpAction's muck

Modified:
    geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandRegistry.java
    geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpAction.java
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandManager.java

Modified: geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandRegistry.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandRegistry.java?rev=698998&r1=698997&r2=698998&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandRegistry.java
(original)
+++ geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandRegistry.java
Thu Sep 25 08:15:03 2008
@@ -19,7 +19,7 @@
 
 package org.apache.geronimo.gshell.command;
 
-import java.util.List;
+import java.util.Collection;
 
 /**
  * Provides registration facilities for {@link Command} instances.
@@ -30,5 +30,5 @@
 {
     CommandRegistration register(Command command);
 
-    List<CommandRegistration> getRegistrations();
+    Collection<CommandRegistration> getRegistrations();
 }
\ No newline at end of file

Modified: geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpAction.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpAction.java?rev=698998&r1=698997&r2=698998&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpAction.java
(original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpAction.java
Thu Sep 25 08:15:03 2008
@@ -34,7 +34,7 @@
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 
-import java.util.List;
+import java.util.Collection;
 
 /**
  * Display command help.
@@ -54,69 +54,84 @@
 
     public Object execute(final CommandContext context) throws Exception {
         assert context != null;
+
+        if (commandName != null) {
+            return displayCommandManual(context);
+        }
+
+        return displayAvailableCommands(context);
+    }
+
+    private Object displayCommandManual(final CommandContext context) {
+        assert context != null;
         IO io = context.getIo();
 
+        log.debug("Displaying help manual for command: {}", commandName);
+
+        // FIXME: Should resolve the commandName/commandPath
+
         assert commandRegistry != null;
-        List<CommandRegistration> registrations = commandRegistry.getRegistrations();
+        Collection<CommandRegistration> registrations = commandRegistry.getRegistrations();
 
-        if (commandName != null) {
-            log.debug("Displaying help manual for command: {}", commandName);
+        for (CommandRegistration registration : registrations) {
+            Command command = registration.getCommand();
+            CommandDocumenter doc = command.getDocumenter();
 
-            // FIXME: Should resolve the commandName/commandPath
-            
-            for (CommandRegistration registration : registrations) {
-                Command command = registration.getCommand();
-                CommandDocumenter doc = command.getDocumenter();
-
-                if (doc.getName().equals(commandName)) {
-                    doc.renderManual(io.out);
-                    
-                    return Result.SUCCESS;
-                }
+            if (doc.getName().equals(commandName)) {
+                doc.renderManual(io.out);
+
+                return Result.SUCCESS;
             }
+        }
 
-            io.out.print("Command ");
-            io.out.print(Renderer.encode(commandName, Code.BOLD));
-            io.out.println(" not found.");
+        io.out.print("Command ");
+        io.out.print(Renderer.encode(commandName, Code.BOLD));
+        io.out.println(" not found.");
 
-            io.out.print("Try ");
-            io.out.print(Renderer.encode("help", Code.BOLD));
-            io.out.println(" for a list of available commands.");
+        io.out.print("Try ");
+        io.out.print(Renderer.encode("help", Code.BOLD));
+        io.out.println(" for a list of available commands.");
 
-            io.out.println();
+        io.out.println();
 
-            return Result.FAILURE;
-        }
-        else {
-            log.debug("Listing brief help for commands");
+        return Result.FAILURE;
+    }
 
-            // FIXME: Figure this out dynamically
-            int maxNameLen = 20;
+    private Object displayAvailableCommands(final CommandContext context) {
+        assert context != null;
+        IO io = context.getIo();
 
-            io.out.println("Available commands:");
-            
-            for (CommandRegistration registration : registrations) {
-                Command command = registration.getCommand();
-                CommandDocumenter doc = command.getDocumenter();
+        log.debug("Listing brief help for commands");
 
-                String name = StringUtils.rightPad(doc.getName(), maxNameLen);
-                String desc = doc.getDescription();
+        // FIXME: Figure this out dynamically
+        int maxNameLen = 20;
 
-                io.out.print("  ");
-                io.out.print(Renderer.encode(name, Code.BOLD));
+        assert commandRegistry != null;
+        Collection<CommandRegistration> registrations = commandRegistry.getRegistrations();
 
-                if (desc != null) {
-                    io.out.print("  ");
-                    io.out.println(desc);
-                }
-                else {
-                    io.out.println();
-                }
-            }
+        io.out.println("Available commands:");
+
+        for (CommandRegistration registration : registrations) {
+            Command command = registration.getCommand();
+            CommandDocumenter doc = command.getDocumenter();
 
-            io.out.println();
+            String name = StringUtils.rightPad(doc.getName(), maxNameLen);
+            String desc = doc.getDescription();
+
+            io.out.print("  ");
+            io.out.print(Renderer.encode(name, Code.BOLD));
+
+            if (desc != null) {
+                io.out.print("  ");
+                io.out.println(desc);
+            }
+            else {
+                io.out.println();
+            }
         }
 
+        io.out.println();
+
         return Result.SUCCESS;
     }
 }

Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandManager.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandManager.java?rev=698998&r1=698997&r2=698998&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandManager.java
(original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandManager.java
Thu Sep 25 08:15:03 2008
@@ -32,6 +32,8 @@
 import org.springframework.beans.factory.annotation.Autowired;
 
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 
 /**
@@ -71,8 +73,8 @@
         return registration;
     }
 
-    public List<CommandRegistration> getRegistrations() {
-        return registrations;
+    public Collection<CommandRegistration> getRegistrations() {
+        return Collections.unmodifiableCollection(registrations);
     }
 
     //



Mime
View raw message