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

GenerateCompletion command only works if used as direct subcommand of root #1051

Closed
charphi opened this issue May 18, 2020 · 5 comments · Fixed by #1056
Closed

GenerateCompletion command only works if used as direct subcommand of root #1051

charphi opened this issue May 18, 2020 · 5 comments · Fixed by #1056
Labels
Milestone

Comments

@charphi
Copy link
Contributor

charphi commented May 18, 2020

I'm trying to use it in a sub-subcommand such as mycommand setup generate-completion
instead of mycommand generate-completion

Unfortunatly, this generates autocompletion for setup and not mycommand.

@remkop remkop added theme: auto-completion An issue or change related to auto-completion type: enhancement ✨ labels May 18, 2020
@remkop
Copy link
Owner

remkop commented May 18, 2020

Yes, currently the AutoComplete.GenerateCompletion command generates completions for its parent. I agree that it would be better if it would generate completions for the root command instead.

Will you be able to provide a pull request (with test) for this?

@remkop
Copy link
Owner

remkop commented May 18, 2020

The implementation for this is fairly straightforward: just replace

String script = AutoComplete.bash(
        spec.parent().name(),
        spec.parent().commandLine());

with

String script = AutoComplete.bash(
        spec.root().name(),
        spec.root().commandLine());

But we do need some tests to verify that this works for your use case (and perhaps another one where the completion command is nested even deeper).

@charphi
Copy link
Contributor Author

charphi commented May 19, 2020

The code is simple indeed.

But, there is one thing missing: a pre-defined variable for root name (ROOT-COMMAND-NAME?) so that the command description
"Generate bash/zsh completion script for ${PARENT-COMMAND-NAME:-the parent command of this command}."
would become:
"Generate bash/zsh completion script for ${ROOT-COMMAND-NAME:-the root command of this command}."

@remkop
Copy link
Owner

remkop commented May 19, 2020

Yes, it makes sense to add a ${ROOT-COMMAND-NAME} variable.

@charphi
Copy link
Contributor Author

charphi commented May 19, 2020

I'm coding a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants