You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fnmain(){#[derive(Clone, clap::ValueEnum)]enumEnum{A,B,C,}// create a dummy command with a subcommand, which in turn takes an enum argletmut app = clap::Command::new("mre").subcommand(
clap::Command::new("subcmd").arg(
clap::Arg::new("arg").required(true).value_parser(clap::builder::EnumValueParser::<Enum>::new()),),);// ask clap_complete to generate completions for the argument following the subcommandlet completions = clap_complete::dynamic::complete(&mut app,vec!["mre".into(),"subcmd".into(),"".into()],2,None,).unwrap();// this will panic because 'A', 'B', 'C' are missing (only '-h' and '--help' are listed)assert!(completions.len() >= 3);}
Steps to reproduce the bug with the above code
cargo run is enough as long as the "unstable-dynamic" is active for clap_complete.
Actual Behaviour
clap_complete doesn't suggest any values for arguments following a subcommand.
Expected Behaviour
It should suggest possible values for arguments following a subcommand.
Additional Context
The reason for this seems fairly straight-forward:
The code responsible for adding the arg value completions uses the pos_index passed into the function to find the correct clap::Arg:
Please complete the following tasks
Rust Version
rustc 1.72.1 (d5c2e9c34 2023-09-13)
Clap Version
clap: 4.4.4, clap_complete: 4.4.1
Minimal reproducible code
Steps to reproduce the bug with the above code
cargo run
is enough as long as the"unstable-dynamic"
is active forclap_complete
.Actual Behaviour
clap_complete doesn't suggest any values for arguments following a subcommand.
Expected Behaviour
It should suggest possible values for arguments following a subcommand.
Additional Context
The reason for this seems fairly straight-forward:
The code responsible for adding the arg value completions uses the
pos_index
passed into the function to find the correctclap::Arg
:clap/clap_complete/src/dynamic/completer.rs
Lines 150 to 155 in 0d9b14f
This fails because the
pos_index
in our example is set to 0. Thepos_index
is always set to 0 when clap_complete encounters a subcommand:clap/clap_complete/src/dynamic/completer.rs
Lines 64 to 68 in 0d9b14f
I fail to see why this is done. If the value is set to 1 instead, the example starts working.
Debug Output
No response
The text was updated successfully, but these errors were encountered: