use clap::{CommandFactory, Parser, ValueEnum};
#[derive(Debug, Parser)]
#[command(version, about, long_about = None)]
struct Cli {
/// What mode to run the program in
#[arg(short, long, value_enum)]
mode: Mode,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
enum Mode {
/// Run swiftly
Fast,
/// Crawl slowly but steadily
///
/// This paragraph is ignored because there is no long help text for possible values.
Slow,
}
fn main() {
let mut cmd = Cli::command();
let args = std::env::args_os().collect::<Vec<_>>();
let arg_index = args.len() - 1;
let r = clap_complete::dynamic::complete(&mut cmd, args, arg_index, None).unwrap();
dbg!(r);
}}
Steps to reproduce the bug with the above code
cargo run -- --mode fast --mo
Actual Behaviour
[src/main.rs:25:5] r = [
(
"--mode",
Some(
StyledStr(
"What mode to run the program in",
),
),
),
]
Expected Behaviour
[src/main.rs:25:5] r = []
Additional Context
Using --mode is invalid, so we should not complete it. Obviously flags that accept multiple values should keep the existing behavior.
Please complete the following tasks
Rust Version
1.76
Clap Version
4.5.2
Minimal reproducible code
Steps to reproduce the bug with the above code
Actual Behaviour
Expected Behaviour
Additional Context
Using
--mode
is invalid, so we should not complete it. Obviously flags that accept multiple values should keep the existing behavior.Debug Output
No response