* - 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 {
}
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<String> duplicatedOptionList = new ArrayList<String>();
-
+
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);
}
}
}
}
}
- //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<String> 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();
+ }
}
+