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/ProfileMappingModifyCLI.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/ProfileMappingModifyCLI.java')
-rw-r--r-- | base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingModifyCLI.java | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingModifyCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingModifyCLI.java index 8a4adc569..22466e80e 100644 --- a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingModifyCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingModifyCLI.java @@ -22,6 +22,7 @@ import java.io.BufferedReader; import java.io.FileReader; import java.io.PrintWriter; import java.io.StringWriter; +import java.util.Arrays; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Option; @@ -40,14 +41,15 @@ public class ProfileMappingModifyCLI extends CLI { public ProfileMappingModifyCLI(ProfileMappingCLI profileMappingCLI) { super("mod", "Modify profile mapping", profileMappingCLI); this.profileMappingCLI = profileMappingCLI; + + createOptions(); } public void printHelp() { formatter.printHelp(getFullName() + " <Profile Mapping ID> [OPTIONS...]", options); } - public void execute(String[] args) throws Exception { - + public void createOptions() { Option option = new Option(null, "action", true, "Action: update (default), approve, reject, enable, disable."); option.setArgName("action"); options.addOption(option); @@ -55,6 +57,15 @@ public class ProfileMappingModifyCLI extends CLI { option = new Option(null, "input", true, "Input file containing 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; @@ -64,20 +75,15 @@ public class ProfileMappingModifyCLI 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 = cmdArgs[0]; @@ -91,7 +97,7 @@ public class ProfileMappingModifyCLI extends CLI { if (input == null) { System.err.println("Error: Missing input file"); printHelp(); - System.exit(1); + System.exit(-1); return; } |