From a2c4c28a0976e25becf85374126f41509c5e59f2 Mon Sep 17 00:00:00 2001 From: Remko Popma Date: Sat, 21 Mar 2020 09:38:50 +0900 Subject: [PATCH] [#969] Reorganized code a little bit to facilitate (hopefully) completion support for nested sub-subcommands; simplify further --- .../java/picocli/shell/jline3/PicocliCommands.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/picocli-shell-jline3/src/main/java/picocli/shell/jline3/PicocliCommands.java b/picocli-shell-jline3/src/main/java/picocli/shell/jline3/PicocliCommands.java index 71a68f982..97ac319a1 100644 --- a/picocli-shell-jline3/src/main/java/picocli/shell/jline3/PicocliCommands.java +++ b/picocli-shell-jline3/src/main/java/picocli/shell/jline3/PicocliCommands.java @@ -78,11 +78,11 @@ public SystemCompleter compileCompleters() { } private SystemCompleter compileCompleters(SystemCompleter completer, CommandLine cmd) { - completer.addAliases(extractAliases(cmd)); - - for (Map.Entry 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? @@ -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 options = new ArrayList<>(); Map> optionValues = new HashMap<>(); for (OptionSpec o : spec.options()) { @@ -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 {