picocli icon indicating copy to clipboard operation
picocli copied to clipboard

Autocomplete mishandling suggestions with spaces

Open jsotuyod opened this issue 2 years ago • 2 comments

When an option provides a completionProvider that list strings with spaces, the autocomplete doesn't honor the completion provider, but instead splits all options on its own.

For instance, given the example:

    @Command(mixinStandardHelpOptions = true)
    public static class DummyCommand {
        @Option(names = "--candidate", completionCandidates = CandidatesCompletion.class)
        public String candidate;

        public static class CandidatesCompletion implements Iterable<String> {

            @Override
            public Iterator<String> iterator() {
                return Arrays.asList("John Doe", "Michael Scott", "John Sena").iterator();
            }
        }
    }

I'd expect 3 candidates to be offered, with proper escaping for the whitespace. However, this is what it's actually being suggested:

$ myapp --candidate <TAB><TAB>
Doe      John     Michael  Scott    Sena

5 options, all single words, duplicates removed.

jsotuyod avatar Jul 27 '22 17:07 jsotuyod

Thank you for raising this! Is this for the bash/zsh completion, or for the JLine completion?

Will you be able to provide a pull request for this?

remkop avatar Jul 28 '22 08:07 remkop

It's on Bash / Zsh. By the time compgen -W is invoked, the list is already plain as John Doe Michael Scott John Sena, so compgen does it's thing.

For what I've seen, escaping here doesn't help, but there are some workarounds… I may give it a go with a PR, but will let you know if I run into trouble.

jsotuyod avatar Jul 28 '22 21:07 jsotuyod