CLI : supports auto suggestion when inputting same option with diffrent main/sub... 52/13452/2
authorshingil.kang <shingil.kang@samsung.com>
Fri, 6 Dec 2013 05:50:10 +0000 (14:50 +0900)
committershingil.kang <shingil.kang@samsung.com>
Fri, 6 Dec 2013 05:53:55 +0000 (14:53 +0900)
Change-Id: Id37e8d6d5863b7719be3f90df479852e29a6202b
Signed-off-by: shingil.kang <shingil.kang@samsung.com>
org.tizen.ncli.ide/src/org/tizen/ncli/ide/autocomplete/TizenAutoComplete.java

index 8893569..496fb81 100644 (file)
@@ -6,7 +6,7 @@
  * Contact:
  * Kangho Kim <kh5325.kim@samsung.com>
  * Hyunsik Noh <hyunsik.noh@samsung.com>
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -39,7 +39,7 @@ public class TizenAutoComplete {
         { "list", "target", "app" },
         { "create", "web-project native-project security-profile security-profile-item certificate" },
         { "help", commands } };
-    
+
     public static String[][] options = {
         { "cli-config", "--list --global" },
         { "build-native", "--predefine-option --arch --compiler --configuration" },
@@ -77,10 +77,11 @@ public class TizenAutoComplete {
         architecture(options[1][0], "--arch", "x86 arm"),
         compiler(options[1][0], "--compiler", "llvm gcc"),
         configuration(options[1][0], "--configuration", "Debug Release DA"),
-        webtemplate(optionsForSub[0][0], "-t", ""),
-        nativetemplate(optionsForSub[1][0], "-t", "");
+        webtemplate(subCommands[1][0], optionsForSub[0][0], "-t", ""),
+        nativetemplate(subCommands[1][0], optionsForSub[1][0], "-t", "");
 
         private String mainCmd;
+        private String subCmd;
         private String option;
         private String suggestion;
 
@@ -94,6 +95,21 @@ public class TizenAutoComplete {
             this.suggestion = suggestion;
         }
 
+        private OptionSuggestion(String mainCmd, String subCmd, String option, String suggestion) {
+            this.mainCmd = mainCmd;
+            this.subCmd = subCmd;
+            this.option = option;
+            this.suggestion = suggestion;
+        }
+
+        public String getMainCmd(){
+            return mainCmd;
+        }
+
+        public String getSubCmd(){
+            return subCmd;
+        }
+
         public String getSuggestion() {
             return suggestion;
         }
@@ -109,15 +125,33 @@ public class TizenAutoComplete {
     public static void main(String[] args) {
         String[] inputs = args;
 
+        String mainCmd = null;
+        String subCmd = null;
+        boolean needSubCmd = false;
+
         int count = inputs.length;
+
+        if (count > 1) {
+            mainCmd = inputs[1];
+            if ((needSubCmd = hasSub(mainCmd))) {
+                if (count > 2) {
+                    subCmd = inputs[2];
+                }
+            }
+        }
+
         if (count > 2) {
             boolean needSuggestion = false;
             OptionSuggestion input = null;
             for (OptionSuggestion optionFortSuggestion : OptionSuggestion.values()) {
                 if (optionFortSuggestion.getOption().equals(inputs[count - 1])) {
-                    needSuggestion = true;
-                    input = optionFortSuggestion;
-                    break;
+                    if(optionFortSuggestion.getMainCmd() == null || optionFortSuggestion.getMainCmd().equals(mainCmd)){
+                        if(optionFortSuggestion.getSubCmd() == null || optionFortSuggestion.getSubCmd().equals(subCmd)){
+                            needSuggestion = true;
+                            input = optionFortSuggestion;
+                            break;
+                        }
+                    }
                 }
             }
             if (needSuggestion) {
@@ -130,18 +164,7 @@ public class TizenAutoComplete {
             }
         }
 
-        String mainCmd = null;
-        String subCmd = null;
-        boolean needSubCmd = false;
 
-        if (count > 1) {
-            mainCmd = inputs[1];
-            if ((needSubCmd = hasSub(mainCmd))) {
-                if (count > 2) {
-                    subCmd = inputs[2];
-                }
-            }
-        }
         System.out.println(getNext(inputs, count, needSubCmd, mainCmd, subCmd));
         return;
     }
@@ -286,7 +309,6 @@ public class TizenAutoComplete {
             suggestion = optionFortSuggestion.getSuggestion();
             break;
         case webtemplate:
-            System.out.println("WEBTEMPLATE");
             List<String> listResult = CreateProjectCommandData.getTemplateList();
             for (String result : listResult) {
                 suggestion = suggestion + " " + result;
@@ -294,14 +316,13 @@ public class TizenAutoComplete {
             suggestion = suggestion.trim();
             break;
         case nativetemplate:
-            System.out.println("NATIVEEMPLATE");
             List<String> nativelistResult = CreateNativeProjectCommandData.getTemplateList();
             for (String result : nativelistResult) {
                 suggestion = suggestion + " " + result;
             }
             suggestion = suggestion.trim();
             break;
-        }        
+        }
         return suggestion;
     }
 }