CLI autocomplete via environment variables vs subcommand #3926
Unanswered
AndreasBackx
asked this question in
Q&A
Replies: 1 comment
-
#3894 has a solution that shows how to do this with a derive. However, yes, an env variable does make this much better. It'd probably be worthwhile to document each approach (env variable, flag, subcommand) with trade offs. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We have a nice macro that automatically adds autocomplete to your Clap CLI. We are currently doing this via a subcommand
generate-completions
. Though we realise that this approach makes it impossible to automatically generate completions for certain CLIs:Imagine we have that very simple CLI and we want to add a subcommand.
foo
is a required argument so if we want to automate the autocomplete generation by addingeval $(cli generate-completions)
or by exporting it to/usr/share/bash-completion/completions/cli
for Bash, the CLI will complain thatfoo
wasn't passed.Therefore it seems right now that we should avoid depending on Clap parsing as part of autocomplete generation. Perhaps the people at Click realised this earlier as that is what they are doing: https://click.palletsprojects.com/en/8.1.x/shell-completion/.
So I have a few questions that spring from this:
Funnily enough we didn't initially face this problem because of how
command_for_update
sets required to false, see #3924.Beta Was this translation helpful? Give feedback.
All reactions