Fixed switch to if statement 41/28641/4
authorburdziak <olaf.burdziakowski@nokia.com>
Fri, 19 Jan 2018 09:12:09 +0000 (10:12 +0100)
committerPatrick Brady <pb071s@att.com>
Fri, 19 Jan 2018 18:39:00 +0000 (18:39 +0000)
Brakets added, initial check is requred before read of first argument.

Issue-ID: APPC-432
Change-Id: Id29d098d1e7358ebc3f53c19cfc60288793253d3
Signed-off-by: burdziak <olaf.burdziakowski@nokia.com>
appc-common/src/main/java/org/onap/appc/CmdLine.java

index d63bd87..383de89 100644 (file)
@@ -29,32 +29,27 @@ import org.onap.appc.encryption.EncryptionTool;
 public class CmdLine {
 
         public static void main(String[] args) {
-        if(args.length <= 1 || args.length >= 3){
-            printUsage();
-        }else{
-            String command = args[0];
-            
-            switch(command){
-                case "encrypt":
-                    if(args[1]!= null){
-                        String clearText = args[1];
-                        String encrypted = EncryptionTool.getInstance().encrypt(clearText);
-                        System.out.println(encrypted);                        
-                    }else{
-                        printUsage();
-                    }
-                    break;
-                default:
-                    printUsage();
-                    break;
-                
+
+            if (args.length < 1) {
+                printUsage();
+                return;
+            }
+
+            String command = args[0];//first parameter
+
+            if (0 == command.compareTo("encrypt") && args.length == 2)//two parameters are required
+            {
+                String clearText = args[1];
+                String encrypted = EncryptionTool.getInstance().encrypt(clearText);
+                System.out.println(encrypted);
+                return;
+            } else {
+                printUsage();
             }
-          }
-            
         }
         
         private static void printUsage(){
             System.out.println("Usage: java -jar <this jar> ...");
             System.out.println("\tencrypt <your text> \t\t(Encrypts your text)");
         }
-}
+}
\ No newline at end of file