summaryrefslogtreecommitdiffstats
path: root/base/java-tools/src/com/netscape/cmstools/profile/ProfileShowCLI.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/profile/ProfileShowCLI.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/profile/ProfileShowCLI.java')
-rw-r--r--base/java-tools/src/com/netscape/cmstools/profile/ProfileShowCLI.java34
1 files changed, 21 insertions, 13 deletions
diff --git a/base/java-tools/src/com/netscape/cmstools/profile/ProfileShowCLI.java b/base/java-tools/src/com/netscape/cmstools/profile/ProfileShowCLI.java
index 64161b842..f5b636c1a 100644
--- a/base/java-tools/src/com/netscape/cmstools/profile/ProfileShowCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/profile/ProfileShowCLI.java
@@ -1,5 +1,7 @@
package com.netscape.cmstools.profile;
+import java.util.Arrays;
+
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.ParseException;
@@ -15,18 +17,29 @@ public class ProfileShowCLI extends CLI {
public ProfileShowCLI(ProfileCLI profileCLI) {
super("show", "Show profiles", profileCLI);
this.profileCLI = profileCLI;
+
+ createOptions();
}
public void printHelp() {
- formatter.printHelp(getFullName() + " <Profile ID>", options);
+ formatter.printHelp(getFullName() + " <Profile ID> [OPTIONS...]", options);
}
- public void execute(String[] args) throws Exception {
- CommandLine cmd = null;
-
+ public void createOptions() {
Option option = new Option(null, "output", true, "Output filename");
option.setArgName("filename");
options.addOption(option);
+ }
+
+ public void execute(String[] args) throws Exception {
+ // 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);
@@ -36,20 +49,15 @@ public class ProfileShowCLI extends CLI {
System.exit(-1);
}
- if (cmd.hasOption("help")) {
- // Display usage
- printHelp();
- System.exit(0);
- }
+ String[] cmdArgs = cmd.getArgs();
- String[] cLineArgs = cmd.getArgs();
- if (cLineArgs.length < 1) {
- System.err.println("Error: Missing profile ID.");
+ if (cmdArgs.length < 1) {
+ System.err.println("Error: No Profile ID specified.");
printHelp();
System.exit(-1);
}
- String profileId = cLineArgs[0];
+ String profileId = cmdArgs[0];
String filename = null;
if (cmd.hasOption("output")) {