Skip to content

Commit

Permalink
[#969] Reorganized code a little bit to facilitate (hopefully) comple…
Browse files Browse the repository at this point in the history
…tion support for nested sub-subcommands; simplify further
  • Loading branch information
remkop committed Mar 21, 2020
1 parent 99ac5c9 commit a2c4c28
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ public SystemCompleter compileCompleters() {
}

private SystemCompleter compileCompleters(SystemCompleter completer, CommandLine cmd) {
completer.addAliases(extractAliases(cmd));

for (Map.Entry<String, CommandLine> entry : cmd.getSubcommands().entrySet()) {
CommandLine sub = entry.getValue();
registerCompleters(completer, entry.getKey(), sub.getCommandSpec());
for (CommandLine sub : cmd.getSubcommands().values()) {
for (String alias : sub.getCommandSpec().aliases()) {
completer.getAliases().put(alias, sub.getCommandName());
}
registerCompleters(completer, sub.getCommandSpec());

// TODO support nested sub-subcommands (https://github.com/remkop/picocli/issues/969)
// Is the below sufficient?
Expand All @@ -91,7 +91,7 @@ private SystemCompleter compileCompleters(SystemCompleter completer, CommandLine
return completer;
}

private void registerCompleters(SystemCompleter out, String commandName, CommandSpec spec) {
private void registerCompleters(SystemCompleter out, CommandSpec spec) {
List<String> options = new ArrayList<>();
Map<String, List<String>> optionValues = new HashMap<>();
for (OptionSpec o : spec.options()) {
Expand All @@ -110,6 +110,7 @@ private void registerCompleters(SystemCompleter out, String commandName, Command
// TODO positional parameter completion
// JLine OptionCompleter need to be improved with option descriptions and option value completion,
// now it completes only strings.
String commandName = spec.name();
if (options.isEmpty() && optionValues.isEmpty()) {
out.add(commandName, new ArgumentCompleter(new StringsCompleter(commandName), NullCompleter.INSTANCE));
} else {
Expand Down

0 comments on commit a2c4c28

Please sign in to comment.