diff options
author | Matthew Harmsen <mharmsen@redhat.com> | 2014-04-25 19:55:35 -0700 |
---|---|---|
committer | Matthew Harmsen <mharmsen@redhat.com> | 2014-04-29 14:19:36 -0700 |
commit | 7b6b60b7d8d26799ea1bda48e6e51fa05854c80e (patch) | |
tree | e51a0d515e8a9a2b9f80dee491fca5217054adf5 /base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingShowCLI.java | |
parent | 05fea2520ae50d74f18017b26f5d58936e29af07 (diff) | |
download | pki-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/tps/profile/ProfileMappingShowCLI.java')
-rw-r--r-- | base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingShowCLI.java | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingShowCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingShowCLI.java index b5820661b..39515221d 100644 --- a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingShowCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingShowCLI.java @@ -20,6 +20,7 @@ package com.netscape.cmstools.tps.profile; import java.io.FileWriter; import java.io.PrintWriter; +import java.util.Arrays; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Option; @@ -38,17 +39,27 @@ public class ProfileMappingShowCLI extends CLI { public ProfileMappingShowCLI(ProfileMappingCLI profileMappingCLI) { super("show", "Show profileMapping", profileMappingCLI); this.profileMappingCLI = profileMappingCLI; + + createOptions(); } public void printHelp() { - formatter.printHelp(getFullName() + " <Profile Mapping ID>", options); + formatter.printHelp(getFullName() + " <Profile Mapping ID> [OPTIONS...]", options); } - public void execute(String[] args) throws Exception { - + public void createOptions() { Option option = new Option(null, "output", true, "Output file to store profile mapping properties."); option.setArgName("file"); 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; @@ -58,20 +69,15 @@ public class ProfileMappingShowCLI extends CLI { } catch (Exception e) { System.err.println("Error: " + e.getMessage()); printHelp(); - System.exit(1); - } - - if (cmd.hasOption("help")) { - // Display usage - printHelp(); - System.exit(0); + System.exit(-1); } String[] cmdArgs = cmd.getArgs(); if (cmdArgs.length != 1) { + System.err.println("Error: No Profile Mapping ID specified."); printHelp(); - System.exit(1); + System.exit(-1); } String profileMappingID = args[0]; |