diff --git a/samples/helloworld/src/main/java/org/springframework/shell/samples/helloworld/commands/HelloWorldCommands.java b/samples/helloworld/src/main/java/org/springframework/shell/samples/helloworld/commands/HelloWorldCommands.java index bed9a749..f4cf6ae5 100644 --- a/samples/helloworld/src/main/java/org/springframework/shell/samples/helloworld/commands/HelloWorldCommands.java +++ b/samples/helloworld/src/main/java/org/springframework/shell/samples/helloworld/commands/HelloWorldCommands.java @@ -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); } } diff --git a/src/main/java/org/springframework/roo/shell/SimpleParser.java b/src/main/java/org/springframework/roo/shell/SimpleParser.java index 79c7ed0d..6331fac9 100644 --- a/src/main/java/org/springframework/roo/shell/SimpleParser.java +++ b/src/main/java/org/springframework/roo/shell/SimpleParser.java @@ -70,7 +70,7 @@ public class SimpleParser implements Parser { * @param cliOptions options * @return mandatory options key */ - private List> getMandatoryOptions(Set cliOptions) { + private List> getMandatoryOptions(Collection cliOptions) { List> mandatoryOptions = new ArrayList>(); 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 unspecified, + String value, SortedSet results) { + StringBuilder strBuilder = new StringBuilder(translated); + if (!translated.endsWith(" ")) { + strBuilder.append(" "); + } + // Plan change for SHL-20. But usability is bad. + /* + List> mandatoryOptions = getMandatoryOptions(unspecified); + for (List 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(".");