Modify help command to make it display command usage and description
information separately to deal with longer descriptions. (FELIX-1145)


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@773611 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/shell/src/main/java/org/apache/felix/shell/impl/HelpCommandImpl.java b/shell/src/main/java/org/apache/felix/shell/impl/HelpCommandImpl.java
index 7a05755..1f3527b 100644
--- a/shell/src/main/java/org/apache/felix/shell/impl/HelpCommandImpl.java
+++ b/shell/src/main/java/org/apache/felix/shell/impl/HelpCommandImpl.java
@@ -1,4 +1,4 @@
-/* 
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -20,6 +20,7 @@
 
 import java.io.PrintStream;
 
+import java.util.StringTokenizer;
 import org.apache.felix.shell.Command;
 import org.apache.felix.shell.ShellService;
 import org.osgi.framework.BundleContext;
@@ -41,12 +42,12 @@
 
     public String getUsage()
     {
-        return "help";
+        return "help [<command> ...]";
     }
 
     public String getShortDescription()
     {
-        return "display impl commands.";
+        return "display all command usage messages or descriptions.";
     }
 
     public void execute(String s, PrintStream out, PrintStream err)
@@ -59,32 +60,49 @@
             if (ref != null)
             {
                 ShellService ss = (ShellService) m_context.getService(ref);
-                String[] cmds = ss.getCommands();
-                String[] usage = new String[cmds.length];
-                String[] desc = new String[cmds.length];
-                int maxUsage = 0;
-                for (int i = 0; i < cmds.length; i++)
+
+                // Parse command line.
+                StringTokenizer st = new StringTokenizer(s, " ");
+
+                // Ignore the command name.
+                st.nextToken();
+
+                if (!st.hasMoreTokens())
                 {
-                    usage[i] = ss.getCommandUsage(cmds[i]);
-                    desc[i] = ss.getCommandDescription(cmds[i]);
-                    // Just in case the command has gone away.
-                    if ((usage[i] != null) && (desc[i] != null))
+                    String[] cmds = ss.getCommands();
+                    for (int i = 0; i < cmds.length; i++)
                     {
-                        maxUsage = Math.max(maxUsage, usage[i].length());
+                        out.println(ss.getCommandUsage(cmds[i]));
                     }
                 }
-                StringBuffer sb = new StringBuffer();
-                for (int i = 0; i < cmds.length; i++)
+                else
                 {
-                    // Just in case the command has gone away.
-                    if ((usage[i] != null) && (desc[i] != null))
+                    String[] cmds = ss.getCommands();
+                    String[] targets = new String[st.countTokens()];
+                    for (int i = 0; i < targets.length; i++)
                     {
-                        sb.delete(0, sb.length());
-                        for (int j = 0; j < (maxUsage - usage[i].length()); j++)
+                        targets[i] = st.nextToken().trim();
+                    }
+                    boolean found = false;
+                    for (int cmdIdx = 0; (cmdIdx < cmds.length); cmdIdx++)
+                    {
+                        for (int targetIdx = 0; targetIdx < targets.length; targetIdx++)
                         {
-                            sb.append(' ');
+                            if (cmds[cmdIdx].equals(targets[targetIdx]))
+                            {
+                                if (found)
+                                {
+                                    out.println("---");
+                                }
+                                found = true;
+                                out.println("Command     : "
+                                    + cmds[cmdIdx]);
+                                out.println("Usage       : "
+                                    + ss.getCommandUsage(cmds[cmdIdx]));
+                                out.println("Description : "
+                                    + ss.getCommandDescription(cmds[cmdIdx]));
+                            }
                         }
-                        out.println(usage[i] + sb + " - " + desc[i]);
                     }
                 }
             }
@@ -96,4 +114,4 @@
             err.println(ex.toString());
         }
     }
-}
+}
\ No newline at end of file
diff --git a/shell/src/main/java/org/apache/felix/shell/impl/LogCommandImpl.java b/shell/src/main/java/org/apache/felix/shell/impl/LogCommandImpl.java
index dca09e8..21f7931 100644
--- a/shell/src/main/java/org/apache/felix/shell/impl/LogCommandImpl.java
+++ b/shell/src/main/java/org/apache/felix/shell/impl/LogCommandImpl.java
@@ -114,7 +114,7 @@
 
     public String getShortDescription()
     {
-        return "list the most recent log entries";
+        return "list the most recent log entries.";
     }
 
     public String getUsage()