summaryrefslogtreecommitdiffstats
path: root/base/java-tools/src/com/netscape/cmstools/key/KeyGenerateCLI.java
diff options
context:
space:
mode:
authorMatthew Harmsen <mharmsen@redhat.com>2014-04-25 19:55:35 -0700
committerMatthew Harmsen <mharmsen@redhat.com>2014-04-29 14:19:36 -0700
commit7b6b60b7d8d26799ea1bda48e6e51fa05854c80e (patch)
treee51a0d515e8a9a2b9f80dee491fca5217054adf5 /base/java-tools/src/com/netscape/cmstools/key/KeyGenerateCLI.java
parent05fea2520ae50d74f18017b26f5d58936e29af07 (diff)
downloadpki-7b6b60b7d8d26799ea1bda48e6e51fa05854c80e.tar.gz
pki-7b6b60b7d8d26799ea1bda48e6e51fa05854c80e.tar.xz
pki-7b6b60b7d8d26799ea1bda48e6e51fa05854c80e.zip
Fixed issue by streamlining code to be more consistent.
* PKI TRAC Ticket #843 - Incorrect CLI argument parsing
Diffstat (limited to 'base/java-tools/src/com/netscape/cmstools/key/KeyGenerateCLI.java')
-rw-r--r--base/java-tools/src/com/netscape/cmstools/key/KeyGenerateCLI.java35
1 files changed, 20 insertions, 15 deletions
diff --git a/base/java-tools/src/com/netscape/cmstools/key/KeyGenerateCLI.java b/base/java-tools/src/com/netscape/cmstools/key/KeyGenerateCLI.java
index 3a2aa86e1..a551d61f3 100644
--- a/base/java-tools/src/com/netscape/cmstools/key/KeyGenerateCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/key/KeyGenerateCLI.java
@@ -18,21 +18,15 @@ public class KeyGenerateCLI extends CLI {
public KeyGenerateCLI(KeyCLI keyCLI) {
super("generate", "Generate key", keyCLI);
this.keyCLI = keyCLI;
+
+ createOptions();
}
public void printHelp() {
- formatter.printHelp(getFullName() + " <Client Key ID> [OPTIONS]", options);
+ formatter.printHelp(getFullName() + " <Client Key ID> --key-algorithm <algorithm> [OPTIONS...]", options);
}
- public void execute(String[] args) {
-
- // Check for "--help" prior to parsing due to required option
- if (Arrays.asList(args).contains("--help")) {
- // Display usage
- printHelp();
- System.exit(0);
- }
-
+ public void createOptions() {
Option option = new Option(null, "key-algorithm", true,
"Algorithm to be used to create a key.\nValid values: AES, DES, DES3, RC2, RC4, DESede.");
option.setArgName("algorithm");
@@ -52,22 +46,33 @@ public class KeyGenerateCLI extends CLI {
+ "\nValid values: wrap, unwrap, sign, verify, encrypt, decrypt.");
option.setArgName("list of usages");
options.addOption(option);
+ }
+
+ public void execute(String[] args) {
+ // Always check for "--help" prior to parsing
+ if (Arrays.asList(args).contains("--help")) {
+ // Display usage
+ printHelp();
+ System.exit(0);
+ }
CommandLine cmd = null;
+
try {
cmd = parser.parse(options, args);
} catch (ParseException e) {
System.err.println("Error: " + e.getMessage());
printHelp();
- System.exit(1);
+ System.exit(-1);
}
String[] cmdArgs = cmd.getArgs();
+
if (cmdArgs.length < 1) {
- System.err.println("Error: Missing the Client Key Id");
+ System.err.println("Error: Missing Client Key Id.");
printHelp();
- System.exit(1);
+ System.exit(-1);
}
String clientKeyId = cmdArgs[0];
@@ -88,11 +93,11 @@ public class KeyGenerateCLI extends CLI {
case KeyRequestResource.RC2_ALGORITHM:
System.err.println("Error: Key size must be specified for the algorithm used.");
printHelp();
- System.exit(1);
+ System.exit(-1);
default:
System.err.println("Error: Algorithm not supported.");
printHelp();
- System.exit(1);
+ System.exit(-1);
}
}
List<String> usages = null;