-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Please complete the following tasks
- I have searched the discussions
- I have searched the open and rejected issues
Clap Version
4.5.51
Describe your use case
I was looking into adding dynamic completions (COMPLETE=shell) support for cargo fuzz. So I'd like to have it complete cargo fuzz <tab>.
By default, clap generates something like this on fish:
complete --keep-order --exclusive --command cargo-fuzz --arguments "(COMPLETE=fish "/path/to/cargo-fuzz" -- (commandline --current-process --tokenize --cut-at-cursor) (commandline --current-token))"Changing that to --command 'cargo' -n '__fish_seen_subcommand_from fuzz' would make it complete cargo fuzz <tab> as well. I'm not sure if the other supported shells support something like this aswell though.
I also tried to do
#[derive(Parser)]
enum CargoArgs {
Fuzz(CargoFuzzSubcommand),
}
#[derive(clap::Args)]
struct CargoFuzzSubcommand {
#[clap(subcommand)]
subcommand: Command,
}
fn main() -> Result<()> {
CompleteEnv::with_factory(CargoArgs::command)
.bin("cargo")
.complete();
}which works on fish, but on bash it completely replaces the original completion instead of adding to it.
Describe the solution you'd like
If something like fishs __fish_seen_subcommand_from can be done on other shells, maybe it could be exposed as
CompleteEnv::with_factory(Command::command)
.bin("cargo")
.only_complete_subcommand("fuzz")
.complete();Alternatives, if applicable
Now that I think about it, it's not cargo-fuzzs responsibility to register completions for cargo.
Perhaps cargos completion script could instead complete unknown subcommands by letting the shell complete cargo-<subcommand> directly. On fish this is very easy with complete --do-complete "cargo-fuzz", again I have no idea how other shells compare here.
Additional Context
No response