Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocompletion doesn't display completion candidates on exact match #1468

Closed
rsenden opened this issue Nov 17, 2021 · 1 comment
Closed

Autocompletion doesn't display completion candidates on exact match #1468

rsenden opened this issue Nov 17, 2021 · 1 comment
Labels
theme: auto-completion An issue or change related to auto-completion type: bug 🐛 type: enhancement ✨
Milestone

Comments

@rsenden
Copy link
Contributor

rsenden commented Nov 17, 2021

Given a subcommand structure like the following:

  • mycmd
    • abc
    • abcdef
      - sub1
      - sub2

There are two issues with the autocompletion script generated by picocli v4.6.2:

  • mycmd abc<TAB><TAB> doesn't display any completion candidates
    • Expected: Display completion candidates: abc and abcdef
  • mycmd abcdef<TAB><TAB> doesn't display any completion candidates
    • Expected: Insert a space and display completion candidates sub1 and sub2

I've had a look at the generated completion script, but given my limited experience with autocomplete scripts I'm not sure how this can be fixed.

@remkop
Copy link
Owner

remkop commented Jan 19, 2022

Thank you for raising this! This is now fixed in master and will be included in the next release.

The cause was that on mycmd abc<TAB><TAB>, the completion script jumps to the _picocli_mycmd_abc function, whereas the desired completion behaviour comes from invoking the _picocli_mycmd function. I updated the autocompletion generator to cater for this special case of an exact match.

Thanks for the example, it was very useful. For reference, I used the following program to match your use case:

@Command(name = "mycmd", mixinStandardHelpOptions = true,
    subcommands = {
        Issue1468.Abc.class,
        Issue1468.Abcdef.class,
        AutoComplete.GenerateCompletion.class})
public class Issue1468 {
    @Command(name = "abc", mixinStandardHelpOptions = true)
    static class Abc {}

    @Command(name = "abcdef", mixinStandardHelpOptions = true)
    static class Abcdef {

        @Command(mixinStandardHelpOptions = true)
        void sub1() {}

        @Command
        void sub2() {}
    }

    public static void main(String[] args) {
        new CommandLine(new Issue1468()).execute("generate-completion");
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: auto-completion An issue or change related to auto-completion type: bug 🐛 type: enhancement ✨
Projects
None yet
Development

No branches or pull requests

2 participants