-
Notifications
You must be signed in to change notification settings - Fork 13
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
add bash completion script #68
Comments
As discussed in #75, it would be worth looking at https://docs.rs/clap_complete/4.1.1/clap_complete/index.html. |
I checked this feature. clap_complete has 3 ways to generate the shell completion. The 1st way is using generate_to, which will generate the shell completion file at compile time. With this way we need to put the generator in The 2nd way is using generate, which could generate the completions file for a specified shell at runtime. But we need to add a # retis -h
Usage: retis [OPTIONS] <COMMAND>
Commands:
collect Collect network events
print Print stored events to stdout
sort Sort stored events in series based on tracking id
pcap Generate a PCAP file from stored events
profile Manage Profiles
Options:
--log-level <LOG_LEVEL> Log level [default: info] [possible values: error, warn, info, debug, trace]
-p, --profile <PROFILE> Comma separated list of profile names to apply
--kconf <KCONF> Path to kernel configuration (e.g. /boot/config-6.3.8-200.fc38.x86_64; default: auto-detect)
-g, --generate <generator> [possible values: bash, elvish, fish, powershell, zsh]
-h, --help Print help (see more with '--help')
-V, --version Print version
# retis -g bash > bash_complete
# source bash_complete The 3rd way is using the unstalbe dynamic feature. With this way we can hide the generate parameter and user will not see it normally. e.g.
Note the 2nd way supports The other question is how to use the completion file after generating? We can't force user to source it every time. Should we add an alise file to source the completion file and execuate
|
Thanks for looking into this, it'll improve the UX by a lot!
Agreed, while generating completion scripts at build time would be best, due to how we handle cli options this is not possible.
Nit: if we go this way I think a
IIUC the 3rd way would be best, as the completion feature would be built-in and would not require our or the user involvement. However I'm not sure how complete is the With that, it looks like the best option for now would be to have a
Please, no. We should either install it as part of the rpm or in the container image, or let the user source it (should be documented in To install the completion script in the rpm or image we would need to generate it though. Maybe this could be done alongside #237 (eg. by calling the resulting binary and generating the completion files once available)? (Not that this is mandatory to get a first implementation in). Or maybe it's possible to call |
From the maintainer's comment, the
OK, let's do it later. When the
|
The clap supports static and unstable-dynamic completion. The static completion supports more shells. But it needs to add a `generate` parameter specifically. While the unstable-dynamic completion could hide the parameter for normal use. This should help if we want to build the complete file in the release package and not disturb normal users. The clap maintainer also said that dynamic completion will replace static completion in future. So I chose to use dynamic completion, although it only supports bash and fish right now. Usage: $ retis complete -h Register shell completions for this program Usage: retis complete --shell <SHELL> --register <REGISTER> [-- <COMP_WORDS>...] Options: --shell <SHELL> Specify shell to complete for [possible values: bash, fish] --register <REGISTER> Path to write completion-registration to -h, --help Print help (see more with '--help') $ retis complete --shell bash --register bash_complete $ source bash_complete Close: retis-org#68 Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
The clap supports static and unstable-dynamic completion. The static completion supports more shells. But it needs to add a `generate` parameter specifically. While the unstable-dynamic completion could hide the parameter for normal use. This should help if we want to build the complete file in the release package and not disturb normal users. The clap maintainer also said that dynamic completion will replace static completion in future. So I chose to use dynamic completion, although it only supports bash and fish right now. Usage: $ retis complete -h Register shell completions for this program Usage: retis complete --shell <SHELL> --register <REGISTER> [-- <COMP_WORDS>...] Options: --shell <SHELL> Specify shell to complete for [possible values: bash, fish] --register <REGISTER> Path to write completion-registration to -h, --help Print help (see more with '--help') $ retis complete --shell bash --register bash_complete $ source bash_complete Close: retis-org#68 Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
As the clap_complete dynamic module is unstable and hard-codes the subcommand as `complete`, which conflicts with the current `collect` subcommand. Let's still use the legacy static way to generate the completion file. Usage: $ retis generate -h Generate completions file for a specified shell Usage: retis generate [OPTIONS] Options: --shell <SHELL> Specify shell to complete for [possible values: bash, elvish, fish, powershell, zsh] --register <REGISTER> Path to write completion-registration to -h, --help Print help $ retis generate --shell bash --register . $ source retis.bash Close: retis-org#68 Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
As the clap_complete dynamic module is unstable and hard-codes the subcommand as `complete`, which conflicts with the current `collect` subcommand. Let's still use the legacy static way to generate the completion file. Usage: $ retis sh-complete -h Generate completions file for a specified shell Usage: retis sh-complete [OPTIONS] Options: --shell <SHELL> Specify shell to complete for [possible values: bash, elvish, fish, powershell, zsh] --register <REGISTER> Path to write completion-registration to -h, --help Print help $ retis sh-complete --shell bash --register . $ source retis.bash Close: retis-org#68 Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
As the clap_complete dynamic module is unstable and hard-codes the subcommand as `complete`, which conflicts with the current `collect` subcommand. Let's still use the legacy static way to generate the completion file. Usage: $ retis sh-complete -h Generate completions file for a specified shell Usage: retis sh-complete [OPTIONS] Options: --shell <SHELL> Specify shell to complete for [possible values: bash, elvish, fish, powershell, zsh] --register <REGISTER> Path to write completion-registration to -h, --help Print help $ retis sh-complete --shell bash --register . $ source retis.bash Close: retis-org#68 Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
As the clap_complete dynamic module is unstable and hard-codes the subcommand as `complete`, which conflicts with the current `collect` subcommand. Let's still use the legacy static way to generate the completion file. Usage: $ retis sh-complete -h Generate completions file for a specified shell Usage: retis sh-complete [OPTIONS] Options: --shell <SHELL> Specify shell to complete for [possible values: bash, elvish, fish, powershell, zsh] --register <REGISTER> Path to write completion-registration to -h, --help Print help $ retis sh-complete --shell bash --register . $ source retis.bash Close: retis-org#68 Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
There's a chance we'll end up having a decent number of options and adding a bash completion file could be a nice to have
The text was updated successfully, but these errors were encountered: