SHL-21 update hint message

This commit is contained in:
Jarred Li
2012-04-15 09:18:49 +08:00
parent d8ec63e26e
commit 74d872bbb5
2 changed files with 40 additions and 13 deletions

View File

@@ -15,11 +15,14 @@ public class HelloWorldCommands implements CommandMarker {
return true;
}
@CliCommand(value = "hw echo", help = "Print a hello world message")
@CliCommand(value = "hw-echo", help = "Print a hello world message")
public void config(
@CliOption(key = { "message" }, mandatory = true, help = "The hello world message") final String message,
@CliOption(key = { "name" }, mandatory = true, help = "The hello world name ") final String name,
@CliOption(key = { "time" }, mandatory = false, help = "The hello world time ") final String time) {
System.out.println("Hello world " + message + "," + name + ". time:" + time);
@CliOption(key = { "name1","name11" }, mandatory = true, help = "The hello world name1 ") final String name1,
@CliOption(key = { "name2","name22" }, mandatory = true, help = "The hello world name2 ") final String name2,
@CliOption(key = { "time" }, mandatory = false, help = "The hello world time ") final String time,
@CliOption(key = { "location" }, mandatory = false, help = "The hello world location ") final String location) {
System.out.println("Hello world " + message + ", name1: " + name1 +
", name2:" + name2 + ". time:" + time + ".location: " + location);
}
}

View File

@@ -70,7 +70,7 @@ public class SimpleParser implements Parser {
* @param cliOptions options
* @return mandatory options key
*/
private List<List<String>> getMandatoryOptions(Set<CliOption> cliOptions) {
private List<List<String>> getMandatoryOptions(Collection<CliOption> cliOptions) {
List<List<String>> mandatoryOptions = new ArrayList<List<String>>();
for (CliOption option : cliOptions) {
if (option.mandatory()) {
@@ -299,7 +299,7 @@ public class SimpleParser implements Parser {
}
//remove the ", " in the end.
String hintForOption = optionBuilder.toString();
hintForOption = hintForOption.substring(0,hintForOption.length()-2);
hintForOption = hintForOption.substring(0, hintForOption.length() - 2);
if (hintForOptions) {
LOGGER.warning(hintForOption + ") for this command");
}
@@ -696,12 +696,7 @@ public class SimpleParser implements Parser {
// Handle normal mandatory options
if (!"".equals(value) && include.mandatory()) {
if (translated.endsWith(" ")) {
results.add(new Completion(translated + "--" + value + " "));
}
else {
results.add(new Completion(translated + " --" + value + " "));
}
handleMandatoryCompletion(translated, unspecified, value, results);
}
}
}
@@ -716,7 +711,7 @@ public class SimpleParser implements Parser {
// Handle completing the option key they're presently typing
if ((lastOptionValue == null || "".equals(lastOptionValue)) && !translated.endsWith(" ")) {
// Given we haven't got an option value of any form, and there's no space at the buffer end, we must still be typing an option key
//System.out.println("completing an option");
for (CliOption option : cliOptions) {
for (String value : option.key()) {
if (value != null && lastOptionKey != null
@@ -867,6 +862,35 @@ public class SimpleParser implements Parser {
}
}
/**
* populate completion for mandatory options
*
* @param translated user's input
* @param unspecified unspecified options
* @param value the option key
* @param results completion list
*/
private void handleMandatoryCompletion(String translated, List<CliOption> unspecified,
String value, SortedSet<Completion> results) {
StringBuilder strBuilder = new StringBuilder(translated);
if (!translated.endsWith(" ")) {
strBuilder.append(" ");
}
// Plan change for SHL-20. But usability is bad.
/*
List<List<String>> mandatoryOptions = getMandatoryOptions(unspecified);
for (List<String> option : mandatoryOptions) {
strBuilder.append("--");
strBuilder.append(option.get(0));
strBuilder.append(" ");
}
*/
strBuilder.append("--");
strBuilder.append(value);
strBuilder.append(" ");
results.add(new Completion(strBuilder.toString()));
}
public void helpReferenceGuide() {
synchronized (mutex) {
File f = new File(".");