summaryrefslogtreecommitdiffstats
path: root/base/java-tools/src/com/netscape/cmstools/profile/ProfileShowCLI.java
diff options
context:
space:
mode:
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")) {