Fix completion in multi word commands

Fixes #150
This commit is contained in:
Eric Bottard
2017-09-16 13:43:04 +02:00
parent 425493e0a9
commit 12dff36d8b
2 changed files with 56 additions and 2 deletions

View File

@@ -58,7 +58,8 @@ public class Shell implements CommandRegistry {
private final ResultHandler resultHandler;
/**
* Marker object returned to signify that there was no input to turn into a command execution.
* Marker object returned to signify that there was no input to turn into a command
* execution.
*/
public static final Object NO_INPUT = new Object();
@@ -243,9 +244,12 @@ public class Shell implements CommandRegistry {
}
private List<CompletionProposal> commandsStartingWith(String prefix) {
// Workaround for https://github.com/spring-projects/spring-shell/issues/150
// (sadly, this ties this class to JLine somehow)
int lastWordStart = prefix.lastIndexOf(' ') + 1;
return methodTargets.entrySet().stream()
.filter(e -> e.getKey().startsWith(prefix))
.map(e -> toCommandProposal(e.getKey(), e.getValue()))
.map(e -> toCommandProposal(e.getKey().substring(lastWordStart), e.getValue()))
.collect(Collectors.toList());
}