You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2013/11/22 10:22:42 UTC

svn commit: r1544443 - in /karaf/trunk/shell/help/src/main: java/org/apache/karaf/shell/help/impl/ resources/OSGI-INF/blueprint/

Author: jbonofre
Date: Fri Nov 22 09:22:42 2013
New Revision: 1544443

URL: http://svn.apache.org/r1544443
Log:
[KARAF-2459] help now uses the completion mode to work better with subshell

Removed:
    karaf/trunk/shell/help/src/main/java/org/apache/karaf/shell/help/impl/SubShellHelpProvider.java
Modified:
    karaf/trunk/shell/help/src/main/java/org/apache/karaf/shell/help/impl/CommandListHelpProvider.java
    karaf/trunk/shell/help/src/main/java/org/apache/karaf/shell/help/impl/SingleCommandHelpProvider.java
    karaf/trunk/shell/help/src/main/resources/OSGI-INF/blueprint/shell-commands.xml

Modified: karaf/trunk/shell/help/src/main/java/org/apache/karaf/shell/help/impl/CommandListHelpProvider.java
URL: http://svn.apache.org/viewvc/karaf/trunk/shell/help/src/main/java/org/apache/karaf/shell/help/impl/CommandListHelpProvider.java?rev=1544443&r1=1544442&r2=1544443&view=diff
==============================================================================
--- karaf/trunk/shell/help/src/main/java/org/apache/karaf/shell/help/impl/CommandListHelpProvider.java (original)
+++ karaf/trunk/shell/help/src/main/java/org/apache/karaf/shell/help/impl/CommandListHelpProvider.java Fri Nov 22 09:22:42 2013
@@ -34,6 +34,7 @@ import org.apache.karaf.shell.commands.b
 import org.apache.karaf.shell.commands.meta.ActionMetaDataFactory;
 import org.apache.karaf.shell.console.HelpProvider;
 import org.apache.karaf.shell.console.NameScoping;
+import org.apache.karaf.shell.console.SessionProperties;
 import org.apache.karaf.shell.table.Col;
 import org.apache.karaf.shell.table.ShellTable;
 import org.fusesource.jansi.Ansi;
@@ -60,11 +61,33 @@ public class CommandListHelpProvider imp
 
     private SortedMap<String, String> getCommandDescriptions(CommandSession session, String command) {
         Set<String> names = (Set<String>) session.get(COMMANDS);
+
+        String subshell = (String) session.get("SUBSHELL");
+        String completionMode = (String) session.get(SessionProperties.COMPLETION_MODE);
+
         SortedMap<String,String> commands = new TreeMap<String,String>();
         for (String name : names) {
+
             if (command != null && !name.startsWith(command)) {
                 continue;
             }
+
+            if (completionMode != null && completionMode.equalsIgnoreCase("subshell")) {
+                // filter the help only for "global" commands
+                if (subshell == null || subshell.trim().isEmpty()) {
+                    if (!name.startsWith("*")) {
+                        continue;
+                    }
+                }
+            }
+
+            if (completionMode != null && (completionMode.equalsIgnoreCase("subshell") || completionMode.equalsIgnoreCase("first"))) {
+                // filter the help only for commands local to the subshell
+                if (!name.startsWith(subshell)) {
+                    continue;
+                }
+            }
+
             String description = null;
             Function function = (Function) session.get(name);
             function = unProxy(function);
@@ -78,6 +101,9 @@ public class CommandListHelpProvider imp
                 if (name.startsWith("*:")) {
                     name = name.substring(2);
                 }
+                if (subshell != null && !subshell.trim().isEmpty() && name.startsWith(subshell)) {
+                    name = name.substring(subshell.length() + 1);
+                }
                 commands.put(name, description);
             }
         }

Modified: karaf/trunk/shell/help/src/main/java/org/apache/karaf/shell/help/impl/SingleCommandHelpProvider.java
URL: http://svn.apache.org/viewvc/karaf/trunk/shell/help/src/main/java/org/apache/karaf/shell/help/impl/SingleCommandHelpProvider.java?rev=1544443&r1=1544442&r2=1544443&view=diff
==============================================================================
--- karaf/trunk/shell/help/src/main/java/org/apache/karaf/shell/help/impl/SingleCommandHelpProvider.java (original)
+++ karaf/trunk/shell/help/src/main/java/org/apache/karaf/shell/help/impl/SingleCommandHelpProvider.java Fri Nov 22 09:22:42 2013
@@ -37,6 +37,15 @@ public class SingleCommandHelpProvider i
     }
 
     public String getHelp(CommandSession session, String path) {
+
+        String subshell = (String) session.get("SUBSHELL");
+
+        if (subshell != null && !subshell.trim().isEmpty()) {
+            if (!path.startsWith(subshell)) {
+                path = subshell + ":" + path;
+            }
+        }
+
         if (path.indexOf('|') > 0) {
             if (path.startsWith("command|")) {
                 path = path.substring("command|".length());

Modified: karaf/trunk/shell/help/src/main/resources/OSGI-INF/blueprint/shell-commands.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/shell/help/src/main/resources/OSGI-INF/blueprint/shell-commands.xml?rev=1544443&r1=1544442&r2=1544443&view=diff
==============================================================================
--- karaf/trunk/shell/help/src/main/resources/OSGI-INF/blueprint/shell-commands.xml (original)
+++ karaf/trunk/shell/help/src/main/resources/OSGI-INF/blueprint/shell-commands.xml Fri Nov 22 09:22:42 2013
@@ -49,11 +49,13 @@
     <bean id="helpSystem" class="org.apache.karaf.shell.help.impl.HelpSystem">
         <argument ref="blueprintBundleContext"/>
     </bean>
-    
+
+    <!--use to get the help on the list of commands -->
     <service interface="org.apache.karaf.shell.console.HelpProvider" ranking="-20">
         <bean class="org.apache.karaf.shell.help.impl.CommandListHelpProvider" />
     </service>
 
+    <!-- use for "help command" syntax -->
     <reference id="threadIO" interface="org.apache.felix.service.threadio.ThreadIO"/>
     <service auto-export="interfaces" ranking="-10">
         <bean class="org.apache.karaf.shell.help.impl.SingleCommandHelpProvider">
@@ -61,11 +63,7 @@
         </bean>
     </service>
 
-    <service auto-export="interfaces" ref="subShellHelpProvider" ranking="-10"/>
-    <bean id="subShellHelpProvider" class="org.apache.karaf.shell.help.impl.SubShellHelpProvider" init-method="start" destroy-method="stop">
-        <property name="context" ref="blueprintBundleContext"/>
-    </bean>
-
+    <!-- use for "help" to get help on each command in the commands list -->
     <service auto-export="interfaces" ranking="-5">
         <bean class="org.apache.karaf.shell.help.impl.SimpleHelpProvider">
             <property name="help">