Add improvements to the help command - to display only the legacy equinox commands, to display only the Gogo type commands, and to display all commands.
Add a Man command, which calls the help command. This is for all users, who are used to using man for getting help.
diff --git a/console/org.eclipse.equinox.console.supportability/src/org/eclipse/equinox/console/command/adapter/Activator.java b/console/org.eclipse.equinox.console.supportability/src/org/eclipse/equinox/console/command/adapter/Activator.java
index eb3972f..a54cdd6 100644
--- a/console/org.eclipse.equinox.console.supportability/src/org/eclipse/equinox/console/command/adapter/Activator.java
+++ b/console/org.eclipse.equinox.console.supportability/src/org/eclipse/equinox/console/command/adapter/Activator.java
@@ -26,6 +26,7 @@
import org.eclipse.equinox.console.commands.DisconnectCommand;
import org.eclipse.equinox.console.commands.EquinoxCommandProvider;
import org.eclipse.equinox.console.commands.HelpCommand;
+import org.eclipse.equinox.console.commands.ManCommand;
import org.eclipse.equinox.console.ssh.SshCommand;
import org.eclipse.equinox.console.telnet.TelnetCommand;
import org.eclipse.osgi.framework.console.CommandInterpreter;
@@ -218,6 +219,9 @@
HelpCommand helpCommand = new HelpCommand(context);
helpCommand.start();
+ ManCommand manCommand = new ManCommand(context);
+ manCommand.start();
+
DisconnectCommand disconnectCommand = new DisconnectCommand(context);
disconnectCommand.start();
}
diff --git a/console/org.eclipse.equinox.console.supportability/src/org/eclipse/equinox/console/commands/HelpCommand.java b/console/org.eclipse.equinox.console.supportability/src/org/eclipse/equinox/console/commands/HelpCommand.java
index 28dd4c2..a036848 100644
--- a/console/org.eclipse.equinox.console.supportability/src/org/eclipse/equinox/console/commands/HelpCommand.java
+++ b/console/org.eclipse.equinox.console.supportability/src/org/eclipse/equinox/console/commands/HelpCommand.java
@@ -90,26 +90,31 @@
* message for the particular command is displayed (if such is defined).
*
* This method can accept an additional argument -legacy. If this option is specified, the names of all
- * legacy equinox commands are displayed, and then the Gogo help command is called to display the other
- * commands' names. If -legacy is not specified, then only the Gogo help command is called.
+ * legacy equinox commands are displayed. If -legacy is not specified, then only the Gogo help command is called.
*
* If -legacy is displayed along with a command name, then the legacy commands are searched
* for a command with this name, and the help message for this command is displayed, if provided. If the
* CommandProvider, which provides this command, does not provide help for individual commands, then
* the help for all commands in the CommandProvider is displayed.
*
+ * This method can accept an additional argument -all. If this option is specified, then both the names of the
+ * legacy equinox commands and the Gogo commands are displayed.
+ *
* @param session
* @param args
* @throws Exception
*/
public void help(final CommandSession session, String... args) throws Exception {
boolean isLegacy = false;
+ boolean isAll = false;
String command = null;
if (args.length > 0) {
for (String arg : args) {
if (arg.equals("-legacy")) {
isLegacy = true;
+ } else if(arg.equals("-all")) {
+ isAll = true;
} else {
command = arg;
}
@@ -142,17 +147,33 @@
return;
}
+ if (isLegacy == false && command != null) {
+ session.execute("help " + command);
+ return;
+ }
+
if (isLegacy == true) {
- for (CommandProvider provider : legacyCommandProviders) {
- Method[] methods = provider.getClass().getMethods();
- for (Method method : methods) {
- if (method.getName().startsWith("_")) {
- System.out.println("equinox:" + method.getName().substring(1));
- }
- }
- }
+ printLegacyCommands();
+ return;
}
+ if (isAll == true) {
+ printLegacyCommands();
+ session.execute("help");
+ return;
+ }
+
session.execute("help");
}
+
+ private void printLegacyCommands() {
+ for (CommandProvider provider : legacyCommandProviders) {
+ Method[] methods = provider.getClass().getMethods();
+ for (Method method : methods) {
+ if (method.getName().startsWith("_")) {
+ System.out.println("equinox:" + method.getName().substring(1));
+ }
+ }
+ }
+ }
}
diff --git a/console/org.eclipse.equinox.console.supportability/src/org/eclipse/equinox/console/commands/ManCommand.java b/console/org.eclipse.equinox.console.supportability/src/org/eclipse/equinox/console/commands/ManCommand.java
new file mode 100644
index 0000000..da5441f
--- /dev/null
+++ b/console/org.eclipse.equinox.console.supportability/src/org/eclipse/equinox/console/commands/ManCommand.java
@@ -0,0 +1,43 @@
+package org.eclipse.equinox.console.commands;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.apache.felix.service.command.CommandProcessor;
+import org.apache.felix.service.command.CommandSession;
+import org.osgi.framework.BundleContext;
+
+public class ManCommand {
+ private BundleContext context;
+
+ public ManCommand(BundleContext context) {
+ this.context = context;
+ }
+
+ public void start() {
+ Dictionary<String, Object> props = new Hashtable<String, Object>();
+ props.put(CommandProcessor.COMMAND_SCOPE, "equinox");
+ props.put(CommandProcessor.COMMAND_FUNCTION, new String[] {"man"});
+ context.registerService(ManCommand.class.getName(), this, props);
+ }
+
+ public void man(CommandSession session, String... args) throws Exception {
+ StringBuilder builder = null;
+ if (args.length > 0) {
+ builder = new StringBuilder();
+ for(String arg : args) {
+ builder.append(arg);
+ builder.append(" ");
+ }
+ }
+
+ String cmdForExecution = null;
+ if (builder != null) {
+ cmdForExecution = "equinox:help" + " " + builder.toString().trim();
+ } else {
+ cmdForExecution = "equinox:help";
+ }
+
+ session.execute(cmdForExecution);
+ }
+}