felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r773611 - in /felix/trunk/shell/src/main/java/org/apache/felix/shell/impl: HelpCommandImpl.java LogCommandImpl.java
Date Mon, 11 May 2009 16:01:39 GMT
Author: rickhall
Date: Mon May 11 16:01:38 2009
New Revision: 773611

URL: http://svn.apache.org/viewvc?rev=773611&view=rev
Log:
Modify help command to make it display command usage and description
information separately to deal with longer descriptions. (FELIX-1145)

Modified:
    felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/HelpCommandImpl.java
    felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/LogCommandImpl.java

Modified: felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/HelpCommandImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/HelpCommandImpl.java?rev=773611&r1=773610&r2=773611&view=diff
==============================================================================
--- felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/HelpCommandImpl.java (original)
+++ felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/HelpCommandImpl.java Mon May
11 16:01:38 2009
@@ -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++)
+                    {
+                        targets[i] = st.nextToken().trim();
+                    }
+                    boolean found = false;
+                    for (int cmdIdx = 0; (cmdIdx < cmds.length); cmdIdx++)
                     {
-                        sb.delete(0, sb.length());
-                        for (int j = 0; j < (maxUsage - usage[i].length()); j++)
+                        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

Modified: felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/LogCommandImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/LogCommandImpl.java?rev=773611&r1=773610&r2=773611&view=diff
==============================================================================
--- felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/LogCommandImpl.java (original)
+++ felix/trunk/shell/src/main/java/org/apache/felix/shell/impl/LogCommandImpl.java Mon May
11 16:01:38 2009
@@ -114,7 +114,7 @@
 
     public String getShortDescription()
     {
-        return "list the most recent log entries";
+        return "list the most recent log entries.";
     }
 
     public String getUsage()



Mime
View raw message