From bff39f7ded97cf92aefa9ffd2892b1cdf0be5272 Mon Sep 17 00:00:00 2001 From: Endi Sukma Dewata Date: Sat, 2 Feb 2013 11:46:57 -0500 Subject: Fixed CLI. --- .../cmstools/cert/CertRequestReviewCLI.java | 32 ++++++++-------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/base/java-tools/src/com/netscape/cmstools/cert/CertRequestReviewCLI.java b/base/java-tools/src/com/netscape/cmstools/cert/CertRequestReviewCLI.java index 06db7db36..774d1f403 100644 --- a/base/java-tools/src/com/netscape/cmstools/cert/CertRequestReviewCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/cert/CertRequestReviewCLI.java @@ -4,6 +4,8 @@ import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.List; import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; @@ -12,6 +14,7 @@ import javax.xml.bind.Unmarshaller; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Option; import org.apache.commons.cli.ParseException; +import org.apache.commons.lang.StringUtils; import com.netscape.certsrv.base.PKIException; import com.netscape.certsrv.cert.CertReviewResponse; @@ -22,6 +25,9 @@ import com.netscape.cmstools.cli.MainCLI; public class CertRequestReviewCLI extends CLI { CertCLI parent; + List actions = Arrays.asList( + "approve", "reject", "cancel", "update", "validate", "assign", "unassign" + ); public CertRequestReviewCLI(CertCLI parent) { super("request-review", "Review certificate request"); @@ -37,7 +43,7 @@ public class CertRequestReviewCLI extends CLI { public void execute(String[] args) throws Exception { CommandLine cmd = null; - Option option = new Option(null, "action", true, "Action (approve/reject/cancel/update/validate/assign/unassign)"); + Option option = new Option(null, "action", true, "Action: " + StringUtils.join(actions, ", ")); option.setArgName("action"); options.addOption(option); @@ -112,28 +118,14 @@ public class CertRequestReviewCLI extends CLI { System.out.println(); while (action == null) { - // Wait for action. - System.out.print("Action (approve/reject/cancel/update/validate/assign/unassign): "); + // Prompt for action. + System.out.print("Action (" + StringUtils.join(actions, "/") + "): "); System.out.flush(); BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); - action = reader.readLine(); - - if (action.equalsIgnoreCase("approve")) { - action = "approve"; - } else if (action.equalsIgnoreCase("reject")) { - action = "reject"; - } else if (action.equalsIgnoreCase("cancel")) { - action = "cancel"; - } else if (action.equalsIgnoreCase("update")) { - action = "update"; - } else if (action.equalsIgnoreCase("validate")) { - action = "validate"; - } else if (action.equalsIgnoreCase("assign")) { - action = "assign"; - } else if (action.equalsIgnoreCase("unassign")) { - action = "unassign"; - } else { + action = reader.readLine().trim().toLowerCase(); + + if (!actions.contains(action)) { action = null; } } -- cgit