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 script doesn't properly handle aliases #1466

Closed
rsenden opened this issue Nov 16, 2021 · 1 comment · Fixed by #1467
Closed

Autocompletion script doesn't properly handle aliases #1466

rsenden opened this issue Nov 16, 2021 · 1 comment · Fixed by #1467
Labels
theme: auto-completion An issue or change related to auto-completion type: bug 🐛
Milestone

Comments

@rsenden
Copy link
Contributor

rsenden commented Nov 16, 2021

I have a command class similar to the following, with sub-commands being programmatically added to this command using commandLine.addSubcommand().

@Command(name = "retrieve", aliases = {"get"}, description = "Get data from various sources")
public class CompositeGetCommand {}

After sourcing the generated auto-completion script, something like mycmd retrieve <TAB><TAB> will correctly list the appropriate sub-commands. However, mycmd get <TAB><TAB> acts like the autocomplete script doesn't recognize the get alias, therefore listing the sub-commands of the mycmd parent command instead:

$ ./mycmd retrieve <TAB><TAB>
sub1 sub2 ...
$ ./mycmd get <TAB><TAB>
get retrieve ...

Looking at the auto-completion script, a duplicate cmd entry is generated for every alias, for example:

  ...
  local cmds7=(retrieve)
  local cmds8=(retrieve)
  ...
  local cmds77=(retrieve sub1)
  local cmds78=(retrieve sub2)
  ...
  local cmds100=(retrieve sub1)
  local cmds101=(retrieve sub2)
  ...

If I manually change this to the following, auto-completion starts working as expected:

  ...
  local cmds7=(retrieve)
  local cmds8=(get)
  ...
  local cmds77=(retrieve sub1)
  local cmds78=(retrieve sub2)
  ...
  local cmds100=(get sub1)
  local cmds101=(get sub2)
  ...

So, it seems like picocli is correctly recognizing aliases, but then incorrectly using the command name instead of alias when generating the autocomplete entries for these aliases.


Edit: The description above is for picocli 4.6.1. I just tried with picocli 4.6.2, where the behavior is slightly different with the following auto-complete script snippet being generated:

  ...
  local cmds7=(retrieve)
  local cmds8=(get)
  ...
  local cmds77=(retrieve sub1)
  local cmds78=(retrieve sub2)
  ...
  local cmds100=(retrieve sub1)
  local cmds101=(retrieve sub2)
  ...

With this, auto-completion works fine for both mycmd retrieve and mycmd get, but not for mycmd get sub1 as cmds100 and cmds101 are still not using the proper alias name.

@remkop remkop added theme: auto-completion An issue or change related to auto-completion type: bug 🐛 labels Nov 16, 2021
@remkop remkop added this to the 4.6.3 milestone Nov 16, 2021
@remkop
Copy link
Owner

remkop commented Nov 16, 2021

@rsenden Thank you for raising this!
Will you be able to provide a pull request to fix this?

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 🐛
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants