This would have been a very nice addition. Although this cannot be currently implemented due to Clap
not having an implementation of generating completions from structs. Though this is possible with the builder pattern
To be honest I don’t understand how clap would help here. At the time I want to see the completion, I’m still entering a line in the CLI, so the program hasn’t started yet.
A clap app has the function generate_completions
to output auto completions for a specific shell into a file. This file is loaded by the shell to provide the completions. The problem with our implementation using structs is that it does not have such a method
No, I get that, but I don’t see how clap
can generate completions for runtime information like what channels the current repo has.
see
Wow, TIL. Thanks for the links!
Clap maintainer here, what’s the issue with generating completions from structs? Opts::into_app()
should give you the built clap::App
Oh Thank you very much. I didn’t knew about the into_app()
method
So, what’s the way to go forward here? I would be willing to help with zsh completions.
Tried to see what clap_complete
offers. The generated script only offers completion for commands/option names, this is as far as clap can go so far (see https://github.com/clap-rs/clap/issues/1232 already mentioned above). I went for the runtime generation since it seems it would be necessary to split the cli building from the bin so that it can be used in the build script.
I can’t believe it took me so long to review this. 2022 was a bit hectic for me, I hope to be back to normal now.
I just applied it to main. Thanks a lot for this patch.
In
git
, if you type e.g.git switch
and hitTab
, you will get a list of all your branches. I don’t know how this kind of completion works, but it would be very nice to have.