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

4.3.2->4.6.1 regression, incorrect autocompletion is generated for subcommand aliases, because of which autocomplete does not work for subcommand specified by alias. #1388

Closed
alfonz19 opened this issue Jul 9, 2021 · 5 comments · Fixed by #1430
Labels
theme: auto-completion An issue or change related to auto-completion type: bug 🐛
Milestone

Comments

@alfonz19
Copy link

alfonz19 commented Jul 9, 2021

TLDR autocompletion does not work for aliases.

Command defined as:

@CommandLine.Command(description = "Receive avro messages from kafka",
        usageHelpWidth = 120,
        name = "receive-avro-from-kafka",
        aliases = {"rafk"})
public class ReceiveAvroMessagesFromKafka extends JsonLikeKafkaMessageReceiver implements Callable<Integer> {

will generate autocompletion:

function _complete_campTools() {
...
  local cmds4=(receive-avro-from-kafka)
  local cmds5=(receive-avro-from-kafka)
...  
  if CompWordsContainsArray "${cmds5[@]}"; then _picocli_campTools_rafk; return $?; fi
  if CompWordsContainsArray "${cmds4[@]}"; then _picocli_campTools_receiveavrofromkafka; return $?; fi
...

_complete_campTools() is top level function. My interpretation is, that cmds4 and cmds5 are generated duplicated. Both subcomand autocomplete functions are equal, but we test presence of wrong word in COMP_WORDS array, meaning that we cannot ever call rafk alias related function. Fixing it to local cmds5=(rafk) fixes the issue and autocomplete works again.

Not sure if that's enough to find the issue, or whether some sub-standard coding on my part causes that. If you need smth more, I can help / share project.

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

remkop commented Jul 9, 2021

Thank you for raising this! That does look like a bug.

Are you interested in providing a pull request for this?

@alfonz19
Copy link
Author

Yes, I'd like to provide it, but it seems that I don't understand the project sufficiently not to create more issues, and I cannot even build master using maven, no idea why... I'd have to invest more time than I have available(hypocrite, I know).

The generating is in picocli.AutoComplete#generateFunctionCallsToArrContains, I'd guess that there is one CommandDescriptor in hierarchy param for each command and it's alias (in my case 2 descriptors for same command), but it's name will be always derived from command name and never from it's alias, so I'd guess error is somewhere in picocli.AutoComplete#createHierarchy. But I can't easily see it or debug the project. I apologize.

@remkop
Copy link
Owner

remkop commented Jul 10, 2021

The project can be built with gradle:

gradle clean build

@alfonz19
Copy link
Author

Sorry, I tried, but I give up. I'm apparently missing some information in several areas including even git (right after clone I have modified files from somewhere and I cannot get rid of them in any way /resetting/checkouting/staging/nothing Is it CRLF line ending normalization issue? Something else?). I don't have sufficient knowledge of gradle/your project to fix this issue; no idea how could I debug building of my project to debug autocomplete generation. I cannot do it in: clone—build—easily debug—fix way, and I cannot afford more. I'd like to help, but I spend like 90m and I'm still stuck just in preparation phase. I don't have more. Sorry.

@remkop
Copy link
Owner

remkop commented Jul 11, 2021

No worries. I’ll take a look when I have some time to spend on picocli again.

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