From: hyunsik.noh Date: Tue, 5 Nov 2013 13:06:33 +0000 (+0900) Subject: CLI: support input suggetion for build-native options(--platform, --toolchain, -... X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d04ff53378db465a26f0ac7d1b50784c11d9e618;p=sdk%2Ftools%2Fcli.git CLI: support input suggetion for build-native options(--platform, --toolchain, --build-target) Fix script to support input suggestion when user use --platform and --toolcahin, --build-target options. Signed-off-by: hyunsik.noh Change-Id: I8ca04caee22009d3ed17d30845478f604ccc4495 --- 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 dbad0e2..e13fb34 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 @@ -23,96 +23,118 @@ * - S-Core Co., Ltd */ package org.tizen.ncli.ide.autocomplete; + import java.util.ArrayList; import java.util.List; +import org.tizen.nativecommon.build.SmartBuildInterface; +import org.tizen.nativecommon.build.exception.SBIException; public class TizenAutoComplete { public static String commands = "build-native build-web cli-config create debug help install list package run sign uninstall"; - - public static String[][] subCommands = { - {"list", "device"}, - {"create", "project security-profile security-profile-item certificate"}, - {"help", commands} - }; - - public static String[][] options = { - {"cli-config", "--list --global"}, - {"build-native", "--predefine-option --platform --toolchain --build-target --build-configuration"}, - {"build-web", "--output -opt --optimize -euf --exclude-uifw -efum --exclude-uifw-min"}, - {"sign", "--profile"}, - {"package", "-t --type --sign -ref --ref-project"}, - {"install", "--target"}, - {"uninstall", "--target"}, - {"run", "--target"}, - {"debug", "--target"} - }; - + + public static String[][] subCommands = { { "list", "device" }, + { "create", "project security-profile security-profile-item certificate" }, { "help", commands } }; + + public static String[][] options = { { "cli-config", "--list --global" }, + { "build-native", "--predefine-option --platform --toolchain --build-target --build-configuration" }, + { "build-web", "--output -opt --optimize -euf --exclude-uifw -efum --exclude-uifw-min" }, { "sign", "--profile" }, + { "package", "-t --type --sign -ref --ref-project" }, { "install", "--target" }, { "uninstall", "--target" }, + { "run", "--target" }, { "debug", "--target" } }; + public static String[][] optionsForSub = { - {"project", "-t --type -n --name"}, - {"security-profile", "--kind --active"}, - {"security-profile-item", "--kind --cert --passwd --ca --rootca"}, - {"certificate", "--password --file-name --country-code --state-name --city-name --user-name --organization-name --department-name --email"}, - {"device", "--detail"} - }; - - public static String[] mainCommandsHaveDuplicatedOptions = { - "create", "build-web", "package" + { "project", "-t --type -n --name" }, + { "security-profile", "--kind --active" }, + { "security-profile-item", "--kind --cert --passwd --ca --rootca" }, + { "certificate", + "--password --file-name --country-code --state-name --city-name --user-name --organization-name --department-name --email" }, + { "device", "--detail" } }; + + public static String[] mainCommandsHaveDuplicatedOptions = { "create", "build-web", "package" }; + + public static String[][] duplicatedOptions = { { "-opt", "--optimize" }, { "-euf", "--exclude-uifw" }, + { "-eufm", "--exclude-uifw-min" }, { "-e", "--exclude" }, { "-t", "--type" }, { "-n", "--name" }, + { "-ref", "--ref-project" } + }; - - public static String[][] duplicatedOptions = { - {"-opt", "--optimize"}, - {"-euf", "--exclude-uifw"}, - {"-eufm", "--exclude-uifw-min"}, - {"-e", "--exclude"}, - {"-t", "--type"}, - {"-n", "--name"}, - {"-ref", "--ref-project"} + + public enum casesForInputSuggestion { + platform("--platform"), toolchain("--toolchain"), buildtarget("--build-target"); - }; + private String option; + + private casesForInputSuggestion(String option) { + this.option = option; + } + + public String getOption() { + return option; + } + } + /** * @param args */ public static void main(String[] args) { - String[] inputs = args[0].trim().split(" "); - + String[] inputs = args; + int count = inputs.length; - 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]; + boolean needSuggestion = false; + casesForInputSuggestion input = null; + for (casesForInputSuggestion optionFortSuggestion : casesForInputSuggestion.values()) { + if (optionFortSuggestion.getOption().equals(inputs[count - 1])) { + needSuggestion = true; + input = optionFortSuggestion; + break; + } + } + + if (needSuggestion) { + try { + System.out.println(makeInputSuggestion(input)); + } catch (SBIException e) { + System.out.println("Faile to get suggestion for " + input.getOption()); + } + return ; + } else { + 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 ; } - System.out.println(getNext(inputs, count, needSubCmd, mainCmd, subCmd)); } - + private static boolean hasSub(String mainCmd) { - for(int i = 0; i < subCommands.length; i++) { - if(subCommands[i][0].equals(mainCmd)) { + for (int i = 0; i < subCommands.length; i++) { + if (subCommands[i][0].equals(mainCmd)) { return true; } } return false; } - + private static String getNext(String[] args, int count, boolean needSubCmd, String mainCmd, String subCmd) { String result = null; - - if(count == 1) { + + if (count == 1) { return getCommand(); } else { - String [][] commands = null; + String[][] commands = null; String criteria = mainCmd; - - if(needSubCmd) { - if(count == 2) { + + if (needSubCmd) { + if (count == 2) { commands = subCommands; return getCommands(commands, criteria); } else { @@ -126,62 +148,61 @@ public class TizenAutoComplete { } return removeExistedOptions(result, args, mainCmd, needSubCmd); } - + private static String getCommand() { return commands; } - + private static String getCommands(String[][] commands, String criteria) { String result = null; - for(int i = 0; i < commands.length ; i++) { - if( commands[i][0].equals(criteria)) { + for (int i = 0; i < commands.length; i++) { + if (commands[i][0].equals(criteria)) { result = commands[i][1]; + break; } } - //case of "help" specially, it returns main commands except "help" - if(subCommands[2][0].equals(criteria)) { + // case of "help" specially, it returns main commands except "help" + if (subCommands[2][0].equals(criteria)) { result = result.replace(criteria, ""); } return result; } - - - //remove candidate if it is already included option + + // remove candidate if it is already included option private static String removeExistedOptions(String candidateString, String[] existedCommands, String mainCmd, boolean hasSubCmd) { - if(candidateString == null) { + if (candidateString == null) { return ""; } - + String result = ""; boolean needDuplicatedCheck = false; - - for(String mainCommand : mainCommandsHaveDuplicatedOptions) { - if(mainCommand.equals(mainCmd)) { + + for (String mainCommand : mainCommandsHaveDuplicatedOptions) { + if (mainCommand.equals(mainCmd)) { needDuplicatedCheck = true; break; } } List duplicatedOptionList = new ArrayList(); - + String[] candidates = candidateString.split(" "); - + String candidate = null; - //no need to check 1st and 2nd command - for(int i = 2; i < existedCommands.length ; i++) { - for(int J = 0 ; J < candidates.length; J++) { + // no need to check 1st and 2nd command + for (int i = 2; i < existedCommands.length; i++) { + for (int J = 0; J < candidates.length; J++) { candidate = candidates[J]; - //if not options, skip. - if('-' != existedCommands[i].charAt(0)) { + // if not options, skip. + if ('-' != existedCommands[i].charAt(0)) { continue; - } else - { - if("".equals(candidate)){ + } else { + if ("".equals(candidate)) { continue; } - if(existedCommands[i].equals(candidate)) { - if(needDuplicatedCheck) { + if (existedCommands[i].equals(candidate)) { + if (needDuplicatedCheck) { String duplicatedOption = findDuplicatedOption(candidate); - if( duplicatedOption != null) { + if (duplicatedOption != null) { duplicatedOptionList.add(duplicatedOption); } } @@ -191,36 +212,59 @@ public class TizenAutoComplete { } } } - //make candidate strinng except duplicated options + // make candidate strinng except duplicated options boolean isFind = false; - for(int i = 0 ; i < candidates.length; i++) { + for (int i = 0; i < candidates.length; i++) { candidate = candidates[i]; isFind = false; - for(String duplicatedOption : duplicatedOptionList) { - if(candidate.equals("") || candidate.equals(duplicatedOption)) { + for (String duplicatedOption : duplicatedOptionList) { + if (candidate.equals("") || candidate.equals(duplicatedOption)) { isFind = true; break; } } - if(!isFind) { + if (!isFind) { result = result + " " + candidate; } } return result.trim(); } - + private static String findDuplicatedOption(String option) { String duplicatedOption = null; int j = 0; - if('-'==(option.charAt(1))) { + if ('-' == (option.charAt(1))) { j = 1; } - for(int i = 0; i < duplicatedOptions.length; i++) { - if(duplicatedOptions[i][j].equals(option)) { - duplicatedOption = duplicatedOptions[i][(1^j)]; + for (int i = 0; i < duplicatedOptions.length; i++) { + if (duplicatedOptions[i][j].equals(option)) { + duplicatedOption = duplicatedOptions[i][(1 ^ j)]; break; } } return duplicatedOption; } + + private static String makeInputSuggestion(casesForInputSuggestion optionFortSuggestion) throws SBIException { + SmartBuildInterface sbi = SmartBuildInterface.getInstance(); + String suggestion = ""; + List listResult = null; + + switch (optionFortSuggestion) { + case platform: + listResult = sbi.getRootstrapList(); + break; + case toolchain: + listResult = sbi.getToolchainList(); + break; + case buildtarget: + listResult = sbi.getTargetList(); + break; + } + for (String result : listResult) { + suggestion = suggestion + " " + result; + } + return suggestion.trim(); + } } + diff --git a/org.tizen.ncli.ide/tizen-autocomplete b/org.tizen.ncli.ide/tizen-autocomplete index 40c2eee..4218b49 100644 --- a/org.tizen.ncli.ide/tizen-autocomplete +++ b/org.tizen.ncli.ide/tizen-autocomplete @@ -1,11 +1,11 @@ _tizen() { - CLASSPATH="" local cur prev args path next COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" - args="" + CLASSPATH="" + ARGS="" for ((i=0; i < ${COMP_CWORD} ; i++)) do @@ -22,10 +22,10 @@ _tizen() MAIN=org.tizen.ncli.ide.autocomplete.TizenAutoComplete - next=$(java -Djava.library.path=SPAWN_LIB_PATH -cp $CLASSPATH $MAIN "$ARGS") + next=$(java -Djava.library.path=SPAWN_LIB_PATH -cp $CLASSPATH $MAIN $ARGS) COMPREPLY=($(compgen -W "${next}" -- ${cur})) return 0 } -complete -F _tizen tizen \ No newline at end of file +complete -F _tizen tizen diff --git a/package/build.linux b/package/build.linux index 5569bf8..64db6e7 100755 --- a/package/build.linux +++ b/package/build.linux @@ -9,7 +9,8 @@ LIB=$SRCDIR/lib NATIVE_LIB=${SRCDIR}/native-lib #newcli NCLI_PROJECT_HOME="org.tizen.ncli.ide" -NCLI_TARGET=package/new-cli.package.$PLATFORM/data/tools/ide +NCLI_PACKAGE_DIR=package/new-cli.package.$PLATFORM +NCLI_TARGET=${NCLI_PACKAGE_DIR}/data/tools/ide NCLI_LIB=${SRCDIR}/new-lib # clean clean() diff --git a/package/new-cli.install.linux b/package/new-cli.install.linux index 941dd16..b164569 100644 --- a/package/new-cli.install.linux +++ b/package/new-cli.install.linux @@ -15,7 +15,7 @@ sed -i "s:LOG_CONFIG_PATH:\"${LOG_CONFIG_PATH}\":g" ${TIZEN_COMPLETION_SCRIPT} sed -i "s:CLI_LIB_PATH:\"${CLI_LIB_PATH}\":g" ${TIZEN_COMPLETION_SCRIPT} sed -i "s:SPAWN_LIB_PATH:\"${SPAWN_LIB_PATH}\":g" ${TIZEN_COMPLETION_SCRIPT} -gksudo "mv ${AUTOCOMPLETE_SRC_SCRIPT} ${TIZEN_COMPLETION_PATH}" +gksudo "mv ${TIZEN_COMPLETION_SCRIPT} ${TIZEN_COMPLETION_PATH}" gksudo "ln -s ${TIZEN_NEWCLI_SH} ${TIZEN_COMPLETION_LINK_PATH}" cd ${CLI_LIB_PATH} diff --git a/package/new-cli.remove.linux b/package/new-cli.remove.linux index dfd5585..3e06906 100644 --- a/package/new-cli.remove.linux +++ b/package/new-cli.remove.linux @@ -6,7 +6,7 @@ TIZEN_COMPLETION_SCRIPT=tizen-autocomplete TIZEN_COMPLETION_PATH=/etc/bash_completion.d TIZEN_COMPLETION_LINK_PATH=/usr/bin/tizen -gksudo "rm ${AUTOCOMPLETE_PATH}/${AUTOCOMPLETE_SCRIPT}" +gksudo "rm ${TIZEN_COMPLETION_PATH}/${TIZEN_COMPLETION_SCRIPT}" gksudo "rm ${TIZEN_COMPLETION_LINK_PATH}" complete -r _tizen tizen