>From cb06ebebc6758ae7e1571ee09074810dc9f33b4f Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Wed, 18 Jan 2017 03:08:02 +0100
Subject: [PATCH] Cleaned up error handling in TPS CLIs.

The TPS CLIs have been modified to use Exceptions instead of
System.exit() such that errors can be handled consistently.
---
 .../tps/authenticator/AuthenticatorAddCLI.java     | 18 +++--------------
 .../tps/authenticator/AuthenticatorFindCLI.java    | 14 ++-----------
 .../tps/authenticator/AuthenticatorModifyCLI.java  | 23 ++++------------------
 .../tps/authenticator/AuthenticatorRemoveCLI.java  | 18 +++--------------
 .../tps/authenticator/AuthenticatorShowCLI.java    | 18 +++--------------
 .../netscape/cmstools/tps/cert/TPSCertFindCLI.java | 20 ++++---------------
 .../netscape/cmstools/tps/cert/TPSCertShowCLI.java | 20 ++++---------------
 .../cmstools/tps/config/ConfigModifyCLI.java       | 18 +++--------------
 .../cmstools/tps/config/ConfigShowCLI.java         | 18 +++--------------
 .../cmstools/tps/connector/ConnectorAddCLI.java    | 18 +++--------------
 .../cmstools/tps/connector/ConnectorFindCLI.java   | 14 ++-----------
 .../cmstools/tps/connector/ConnectorModifyCLI.java | 23 ++++------------------
 .../cmstools/tps/connector/ConnectorRemoveCLI.java | 18 +++--------------
 .../cmstools/tps/connector/ConnectorShowCLI.java   | 18 +++--------------
 .../cmstools/tps/profile/ProfileAddCLI.java        | 18 +++--------------
 .../cmstools/tps/profile/ProfileFindCLI.java       | 14 ++-----------
 .../cmstools/tps/profile/ProfileMappingAddCLI.java | 18 +++--------------
 .../tps/profile/ProfileMappingFindCLI.java         | 14 ++-----------
 .../tps/profile/ProfileMappingModifyCLI.java       | 23 ++++------------------
 .../tps/profile/ProfileMappingRemoveCLI.java       | 18 +++--------------
 .../tps/profile/ProfileMappingShowCLI.java         | 20 ++++---------------
 .../cmstools/tps/profile/ProfileModifyCLI.java     | 23 ++++------------------
 .../cmstools/tps/profile/ProfileRemoveCLI.java     | 18 +++--------------
 .../cmstools/tps/profile/ProfileShowCLI.java       | 18 +++--------------
 .../netscape/cmstools/tps/token/TokenAddCLI.java   | 18 +++--------------
 .../netscape/cmstools/tps/token/TokenFindCLI.java  | 14 ++-----------
 .../cmstools/tps/token/TokenModifyCLI.java         | 22 ++++-----------------
 .../cmstools/tps/token/TokenRemoveCLI.java         | 18 +++--------------
 .../netscape/cmstools/tps/token/TokenShowCLI.java  | 18 +++--------------
 29 files changed, 90 insertions(+), 442 deletions(-)

diff --git a/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorAddCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorAddCLI.java
index 52475094790ceec52b90b9ec7470c8dcf59ba9d3..5ae04afa5f31d0cd9269b5177616a07e354c51e8 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorAddCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorAddCLI.java
@@ -59,28 +59,16 @@ public class AuthenticatorAddCLI extends CLI {
     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);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 0) {
-            System.err.println("Error: Too many arguments specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("Too many arguments specified.");
         }
 
         String input = cmd.getOptionValue("input");
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorFindCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorFindCLI.java
index 58532de554f465e4ecdb06f5c389d66d4e779f24..778f370f00efb34ce7e35a1731e9ba7282e417ca 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorFindCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorFindCLI.java
@@ -60,21 +60,11 @@ public class AuthenticatorFindCLI extends CLI {
     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);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
         String filter = cmdArgs.length > 0 ? cmdArgs[0] : null;
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorModifyCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorModifyCLI.java
index 410f0b744f9587eeef3e716edb1adc6383bb05c9..db5849b3191c1dc87dffdd54b07ee96b40c9abd4 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorModifyCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorModifyCLI.java
@@ -62,28 +62,16 @@ public class AuthenticatorModifyCLI extends CLI {
     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);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 1) {
-            System.err.println("Error: No Authenticator ID specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("No Authenticator ID specified.");
         }
 
         String authenticatorID = cmdArgs[0];
@@ -95,10 +83,7 @@ public class AuthenticatorModifyCLI extends CLI {
         if (action.equals("update")) {
 
             if (input == null) {
-                System.err.println("Error: Missing input file");
-                printHelp();
-                System.exit(-1);
-                return;
+                throw new Exception("Missing input file");
             }
 
             try (BufferedReader in = new BufferedReader(new FileReader(input));
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorRemoveCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorRemoveCLI.java
index f9352c6bf5cc6195d9517555f6994f2c3fb69fc5..1e40873db63b88bfe4c24c80ed62b80ae3be0cc6 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorRemoveCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorRemoveCLI.java
@@ -44,28 +44,16 @@ public class AuthenticatorRemoveCLI extends CLI {
     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);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 1) {
-            System.err.println("Error: No Authenticator ID specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("No Authenticator ID specified.");
         }
 
         String authenticatorID = args[0];
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorShowCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorShowCLI.java
index 65da2028cada95b053eb6bf0e8f3156bece4456e..6df9129c069f0383023be4a398054e38d8e35fa3 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorShowCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorShowCLI.java
@@ -56,28 +56,16 @@ public class AuthenticatorShowCLI extends CLI {
     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);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 1) {
-            System.err.println("Error: No Authenticator ID specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("No Authenticator ID specified.");
         }
 
         String authenticatorID = args[0];
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/cert/TPSCertFindCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/cert/TPSCertFindCLI.java
index 83c977ba978c03837012709317f5fdfd80cec173..bea4266c0c473fcd6020068fc8e8de7764b65eec 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/cert/TPSCertFindCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/cert/TPSCertFindCLI.java
@@ -64,21 +64,11 @@ public class TPSCertFindCLI extends CLI {
     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);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
         String filter = cmdArgs.length > 0 ? cmdArgs[0] : null;
@@ -92,15 +82,13 @@ public class TPSCertFindCLI extends CLI {
         try {
             start = string3 == null ? null : Integer.valueOf(string3);
         } catch (NumberFormatException e) {
-            System.err.println("Error: Invalid value for --start parameter: " + string3);
-            System.exit(-1);
+            throw new Exception("Invalid value for --start parameter: " + string3, e);
         }
 
         try {
             size = string4 == null ? null : Integer.valueOf(string4);
         } catch (NumberFormatException e) {
-            System.err.println("Error: Invalid value for --size parameter: " + string4);
-            System.exit(-1);
+            throw new Exception("Invalid value for --size parameter: " + string4, e);
         }
 
         TPSCertCollection result = certCLI.certClient.findCerts(filter, tokenID, start, size);
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/cert/TPSCertShowCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/cert/TPSCertShowCLI.java
index 24513a68322e870bf8de618755e15c8c853fca11..16eaaf25b34d07d3f7c4de9450d2509f35d51b49 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/cert/TPSCertShowCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/cert/TPSCertShowCLI.java
@@ -45,31 +45,19 @@ public class TPSCertShowCLI extends CLI {
     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);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 1) {
-            System.err.println("Error: No Certificate ID specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("No Certificate ID specified.");
         }
 
-        String certID = args[0];
+        String certID = cmdArgs[0];
 
         TPSCertData certData = certCLI.certClient.getCert(certID);
 
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/config/ConfigModifyCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/config/ConfigModifyCLI.java
index 1136b0932f87d684a21a5f045c04474fde222db0..c5da9431087aaa22640ea1b6e281847af9977384 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/config/ConfigModifyCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/config/ConfigModifyCLI.java
@@ -64,28 +64,16 @@ public class ConfigModifyCLI extends CLI {
     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);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 0) {
-            System.err.println("Error: Too many arguments specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("Too many arguments specified.");
         }
 
         String input = cmd.getOptionValue("input");
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/config/ConfigShowCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/config/ConfigShowCLI.java
index 90c4c04569a2e91020f2ef7d602de772dfc446b0..d7f20e80da329aa3bb1b954c3a893fd736cb45d1 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/config/ConfigShowCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/config/ConfigShowCLI.java
@@ -56,28 +56,16 @@ public class ConfigShowCLI extends CLI {
     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);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 0) {
-            System.err.println("Error: Too many arguments specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("Too many arguments specified.");
         }
 
         String output = cmd.getOptionValue("output");
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorAddCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorAddCLI.java
index acc55f4c97e83f6921c7f42147d0bc72ae2bd2f6..2591fe20e43eaeee84dbf7f933fc926c9fc1985f 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorAddCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorAddCLI.java
@@ -59,28 +59,16 @@ public class ConnectorAddCLI extends CLI {
     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);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 0) {
-            System.err.println("Error: Too many arguments specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("Too many arguments specified.");
         }
 
         String input = cmd.getOptionValue("input");
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorFindCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorFindCLI.java
index 8e1e39f2009caa8a802e7411b9a988576c35c46b..a2297c70574571af3441d8a2ddf2ae30d8b2db68 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorFindCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorFindCLI.java
@@ -60,21 +60,11 @@ public class ConnectorFindCLI extends CLI {
     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);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
         String filter = cmdArgs.length > 0 ? cmdArgs[0] : null;
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorModifyCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorModifyCLI.java
index 8180934dc4a8e60a6d5274bb9a6524e975d7caf1..1de707402ddd786e8dcc487c10352eac3d5caa76 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorModifyCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorModifyCLI.java
@@ -62,28 +62,16 @@ public class ConnectorModifyCLI extends CLI {
     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);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 1) {
-            System.err.println("Error: No Connector ID specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("No Connector ID specified.");
         }
 
         String connectorID = cmdArgs[0];
@@ -95,10 +83,7 @@ public class ConnectorModifyCLI extends CLI {
         if (action.equals("update")) {
 
             if (input == null) {
-                System.err.println("Error: Missing input file");
-                printHelp();
-                System.exit(-1);
-                return;
+                throw new Exception("Missing input file");
             }
 
             try (BufferedReader in = new BufferedReader(new FileReader(input));
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorRemoveCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorRemoveCLI.java
index 97df9523059506cc9b5bc3d824b4ef4510f3466a..577d73111139c30df0571ee8e747575d4ab0b53b 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorRemoveCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorRemoveCLI.java
@@ -44,28 +44,16 @@ public class ConnectorRemoveCLI extends CLI {
     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);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 1) {
-            System.err.println("Error: No Connector ID specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("No Connector ID specified.");
         }
 
         String connectorID = args[0];
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorShowCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorShowCLI.java
index dacccf2e28d61357ef129bba38a93922e9c098a5..0918461e307c360e1be35f6f326c29251b7c721e 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorShowCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorShowCLI.java
@@ -56,28 +56,16 @@ public class ConnectorShowCLI extends CLI {
     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);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 1) {
-            System.err.println("Error: No Connector ID specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("No Connector ID specified.");
         }
 
         String connectorID = args[0];
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileAddCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileAddCLI.java
index 11fbb21c43892add00905f7eff270a01f7ffe273..1f5cec65667bd197364ebf0c4331652517642de5 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileAddCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileAddCLI.java
@@ -59,28 +59,16 @@ public class ProfileAddCLI extends CLI {
     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);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 0) {
-            System.err.println("Error: Too many arguments specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("Too many arguments specified.");
         }
 
         String input = cmd.getOptionValue("input");
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileFindCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileFindCLI.java
index b9182620cf08b40e0b827c5e5dac4a34da638b57..d07c542252409d6a79289e9dd20624f65385373f 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileFindCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileFindCLI.java
@@ -60,21 +60,11 @@ public class ProfileFindCLI extends CLI {
     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);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
         String filter = cmdArgs.length > 0 ? cmdArgs[0] : null;
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingAddCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingAddCLI.java
index 65958cb4fa4d3ca0235fa3067b207a48b2266482..3fd67bdbc708057cc71f050e514a05025ee785b5 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingAddCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingAddCLI.java
@@ -59,28 +59,16 @@ public class ProfileMappingAddCLI extends CLI {
     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);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 0) {
-            System.err.println("Error: Too many arguments specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("Too many arguments specified.");
         }
 
         String input = cmd.getOptionValue("input");
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingFindCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingFindCLI.java
index d3a63f56b21dd33662471f1d958ba501e1bf6f93..e28090064613532e3d4e2e7161abc4910754c469 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingFindCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingFindCLI.java
@@ -60,21 +60,11 @@ public class ProfileMappingFindCLI extends CLI {
     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);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
         String filter = cmdArgs.length > 0 ? cmdArgs[0] : null;
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 22466e80ed8b750f0472ab935758c1f2a9ad4655..3296e2c3cac0c96c47a5f8f538cb33a5a8dd4696 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
@@ -62,28 +62,16 @@ public class ProfileMappingModifyCLI extends CLI {
     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);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 1) {
-            System.err.println("Error: No Profile Mapping ID specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("No Profile Mapping ID specified.");
         }
 
         String profileMappingID = cmdArgs[0];
@@ -95,10 +83,7 @@ public class ProfileMappingModifyCLI extends CLI {
         if (action.equals("update")) {
 
             if (input == null) {
-                System.err.println("Error: Missing input file");
-                printHelp();
-                System.exit(-1);
-                return;
+                throw new Exception("Missing input file");
             }
 
             try (BufferedReader in = new BufferedReader(new FileReader(input));
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingRemoveCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingRemoveCLI.java
index 484bda2a01cb8b2c455d20014bc574d2fd4993fc..1d1c9d84cb90de866cec9a90948985814dc9c63f 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingRemoveCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingRemoveCLI.java
@@ -44,28 +44,16 @@ public class ProfileMappingRemoveCLI extends CLI {
     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);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 1) {
-            System.err.println("Error: No Profile Mapping ID specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("No Profile Mapping ID specified.");
         }
 
         String profileMappingID = args[0];
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 39515221d1ffe4521d58baea4551f4d8abf9acf2..0aa6ec092c7598bafdcd43c52902bfeeff98fd41 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
@@ -56,31 +56,19 @@ public class ProfileMappingShowCLI extends CLI {
     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);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 1) {
-            System.err.println("Error: No Profile Mapping ID specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("No Profile Mapping ID specified.");
         }
 
-        String profileMappingID = args[0];
+        String profileMappingID = cmdArgs[0];
         String output = cmd.getOptionValue("output");
 
         ProfileMappingData profileMappingData = profileMappingCLI.profileMappingClient.getProfileMapping(profileMappingID);
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileModifyCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileModifyCLI.java
index c042552abe387511689b00a784cdcfca25313631..e51740cf783997d9f9e9af2a61f1957e3b9265f5 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileModifyCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileModifyCLI.java
@@ -62,28 +62,16 @@ public class ProfileModifyCLI extends CLI {
     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);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 1) {
-            System.err.println("Error: No Profile ID specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("No Profile ID specified.");
         }
 
         String profileID = cmdArgs[0];
@@ -95,10 +83,7 @@ public class ProfileModifyCLI extends CLI {
         if (action.equals("update")) {
 
             if (input == null) {
-                System.err.println("Error: Missing input file");
-                printHelp();
-                System.exit(-1);
-                return;
+                throw new Exception("Missing input file");
             }
 
             try (BufferedReader in = new BufferedReader(new FileReader(input));
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileRemoveCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileRemoveCLI.java
index 4aca086ecee118952f7ffdb1be8275d61a04ad8c..e77f72ac04bae4f9d7f9d0112de82e5cec1cf23c 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileRemoveCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileRemoveCLI.java
@@ -44,28 +44,16 @@ public class ProfileRemoveCLI extends CLI {
     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);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 1) {
-            System.err.println("Error: No Profile ID specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("No Profile ID specified.");
         }
 
         String profileID = args[0];
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileShowCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileShowCLI.java
index 1a4f8a81fef28d250a5121e74c49cea88d09d0ce..b273f5fd5461efc0b47ab55b6e3e50e1468b6acb 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileShowCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileShowCLI.java
@@ -56,28 +56,16 @@ public class ProfileShowCLI extends CLI {
     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);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 1) {
-            System.err.println("Error: No Profile ID specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("No Profile ID specified.");
         }
 
         String profileID = args[0];
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenAddCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenAddCLI.java
index 1615846d6b6ae91c74cb87dda2e48667c24ff811..847a9967a9a13380cdfb93bacd3d7c75e3361579 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenAddCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenAddCLI.java
@@ -58,28 +58,16 @@ public class TokenAddCLI extends CLI {
     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);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 1) {
-            System.err.println("Error: No Token ID specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("No Token ID specified.");
         }
 
         String tokenID = cmdArgs[0];
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenFindCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenFindCLI.java
index 477d6d926c507ca5dc972ef434a0d85d09042791..d2ecde91b89f3a174d2a508475d303db9f0f612f 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenFindCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenFindCLI.java
@@ -77,21 +77,11 @@ public class TokenFindCLI extends CLI {
     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);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
         String filter = cmdArgs.length > 0 ? cmdArgs[0] : null;
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenModifyCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenModifyCLI.java
index a5eac68d29696fd8705496fec4fb6c415b581480..abc383e643ffd8c66ab72348b6ff9802732046e1 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenModifyCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenModifyCLI.java
@@ -63,28 +63,16 @@ public class TokenModifyCLI extends CLI {
     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);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 1) {
-            System.err.println("Error: No Token ID specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("No Token ID specified.");
         }
 
         TokenData tokenData = new TokenData();
@@ -115,9 +103,7 @@ public class TokenModifyCLI extends CLI {
         }
 
         if (!modify && status == null) {
-            System.err.println("Error: No modifications specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("No modifications specified.");
         }
 
         MainCLI.printMessage("Modified token \"" + tokenID + "\"");
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenRemoveCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenRemoveCLI.java
index 5dd06895d6eaaf382d985a64abd53ec85bd502c6..10446fd9e46ab6ceaa0c36a90850061bcbef33a4 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenRemoveCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenRemoveCLI.java
@@ -44,28 +44,16 @@ public class TokenRemoveCLI extends CLI {
     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);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 1) {
-            System.err.println("Error: No Token ID specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("No Token ID specified.");
         }
 
         String tokenID = args[0];
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenShowCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenShowCLI.java
index eb243f38a9a9518946abb527a8cfaad8831c142a..19237937ca301ab04a0eb7039e7305cb5513c5b3 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenShowCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenShowCLI.java
@@ -45,28 +45,16 @@ public class TokenShowCLI extends CLI {
     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);
+            return;
         }
 
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-
-        } catch (Exception e) {
-            System.err.println("Error: " + e.getMessage());
-            printHelp();
-            System.exit(-1);
-        }
+        CommandLine cmd = parser.parse(options, args);
 
         String[] cmdArgs = cmd.getArgs();
 
         if (cmdArgs.length != 1) {
-            System.err.println("Error: No Token ID specified.");
-            printHelp();
-            System.exit(-1);
+            throw new Exception("No Token ID specified.");
         }
 
         String tokenID = args[0];
-- 
2.5.5

