From aacff0842c31c2639af20cc564f7e0b034085884 Mon Sep 17 00:00:00 2001 From: "shingil.kang" Date: Fri, 6 Dec 2013 14:50:10 +0900 Subject: [PATCH] CLI : supports auto suggestion when inputting same option with diffrent main/sub command. Change-Id: Id37e8d6d5863b7719be3f90df479852e29a6202b Signed-off-by: shingil.kang --- .../ncli/ide/autocomplete/TizenAutoComplete.java | 63 ++++++++++++++-------- 1 file changed, 42 insertions(+), 21 deletions(-) diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/autocomplete/TizenAutoComplete.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/autocomplete/TizenAutoComplete.java index 8893569..496fb81 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/autocomplete/TizenAutoComplete.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/autocomplete/TizenAutoComplete.java @@ -6,7 +6,7 @@ * Contact: * Kangho Kim * Hyunsik Noh - * + * * 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 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 nativelistResult = CreateNativeProjectCommandData.getTemplateList(); for (String result : nativelistResult) { suggestion = suggestion + " " + result; } suggestion = suggestion.trim(); break; - } + } return suggestion; } } -- 2.7.4