summaryrefslogtreecommitdiffstats
path: root/base/java-tools
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2013-11-13 12:23:30 -0500
committerEndi S. Dewata <edewata@redhat.com>2013-11-14 16:54:48 -0500
commit0aab0a6d60f139e958020cc59e07faf9517c235b (patch)
tree58711e23045883b69e08af4ac8735fe3e8ef940d /base/java-tools
parent4d1ec71c790e467ecae184df01abf825f94d1dc3 (diff)
downloadpki-0aab0a6d60f139e958020cc59e07faf9517c235b.tar.gz
pki-0aab0a6d60f139e958020cc59e07faf9517c235b.tar.xz
pki-0aab0a6d60f139e958020cc59e07faf9517c235b.zip
Fixed CLI command parsing.
The CLI command parsing has been fixed such that it consumes all parts of the commands. If there's unprocessed component it means it is an invalid command. Ticket #787
Diffstat (limited to 'base/java-tools')
-rw-r--r--base/java-tools/src/com/netscape/cmstools/cli/CLI.java45
-rw-r--r--base/java-tools/src/com/netscape/cmstools/cli/ProxyCLI.java6
2 files changed, 38 insertions, 13 deletions
diff --git a/base/java-tools/src/com/netscape/cmstools/cli/CLI.java b/base/java-tools/src/com/netscape/cmstools/cli/CLI.java
index 6bd7d69ab..4e904c2ad 100644
--- a/base/java-tools/src/com/netscape/cmstools/cli/CLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/cli/CLI.java
@@ -97,6 +97,10 @@ public class CLI {
return getClass().getAnnotation(Deprecated.class) != null;
}
+ public Collection<CLI> getModules() {
+ return modules.values();
+ }
+
public CLI getModule(String name) {
return modules.get(name);
}
@@ -181,11 +185,11 @@ public class CLI {
// For example: cert-request-find
String command = args[0];
- // The command will be split into module name and module command, for example:
+ // The command will be split into module name and sub command, for example:
// - module name: cert
- // - module command: request-find
+ // - sub command: request-find
String moduleName = null;
- String moduleCommand = null;
+ String subCommand = null;
// Search the module by incrementally adding parts into module name.
// Repeat until it finds the module or until there is no more parts to add.
@@ -197,21 +201,36 @@ public class CLI {
// Find the next dash.
int i = command.indexOf('-', position);
if (i >= 0) {
- // If dash found, split command.
+ // Dash found. Split command into module name and sub command.
moduleName = command.substring(0, i);
- moduleCommand = command.substring(i+1);
+ subCommand = command.substring(i+1);
} else {
- // If dash not found, use the whole command.
+ // Dash not found. Use the whole command.
moduleName = command;
- moduleCommand = null;
+ subCommand = null;
}
// Find module with that name.
- module = getModule(moduleName);
-
- // If module found, stop.
- if (module != null) break;
+ CLI m = getModule(moduleName);
+
+ if (m != null) {
+ // Module found. Check sub command.
+ if (subCommand == null) {
+ // No sub command. Use this module.
+ module = m;
+ break;
+ }
+
+ // There is a sub command. It must be processed by module's children.
+ if (!m.getModules().isEmpty()) {
+ // Module has children. Use this module.
+ module = m;
+ break;
+ }
+
+ // Module doesn't have children. Keep looking.
+ }
// If there's no more dashes, stop.
if (i < 0) break;
@@ -227,10 +246,10 @@ public class CLI {
// Prepare module arguments.
String[] moduleArgs;
- if (moduleCommand != null) {
+ if (subCommand != null) {
// If module command exists, include it as arguments: <module command> <args>...
moduleArgs = new String[args.length];
- moduleArgs[0] = moduleCommand;
+ moduleArgs[0] = subCommand;
System.arraycopy(args, 1, moduleArgs, 1, args.length-1);
} else {
diff --git a/base/java-tools/src/com/netscape/cmstools/cli/ProxyCLI.java b/base/java-tools/src/com/netscape/cmstools/cli/ProxyCLI.java
index 7d76cb1b2..c5387cf03 100644
--- a/base/java-tools/src/com/netscape/cmstools/cli/ProxyCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/cli/ProxyCLI.java
@@ -18,6 +18,8 @@
package com.netscape.cmstools.cli;
+import java.util.Collection;
+
import com.netscape.certsrv.account.AccountClient;
import com.netscape.certsrv.client.ClientConfig;
import com.netscape.certsrv.client.PKIClient;
@@ -69,6 +71,10 @@ public class ProxyCLI extends CLI {
return module.getParent();
}
+ public Collection<CLI> getModules() {
+ return module.getModules();
+ }
+
public CLI getModule(String name) {
return module.getModule(name);
}