From 3eaf1af052bd5255cc2440dc1cc8f80831a3428b Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 8 Jan 2024 09:58:42 -0600 Subject: [PATCH] fix(help): Correctly show help for fake flags --- clap_builder/src/builder/arg.rs | 4 +++- clap_builder/src/builder/debug_asserts.rs | 15 ++++++++------- clap_mangen/src/render.rs | 4 ++-- examples/find.md | 12 +++++------- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/clap_builder/src/builder/arg.rs b/clap_builder/src/builder/arg.rs index f83b4642c16..1a1bdb134a3 100644 --- a/clap_builder/src/builder/arg.rs +++ b/clap_builder/src/builder/arg.rs @@ -4078,7 +4078,9 @@ impl Arg { } pub(crate) fn is_takes_value_set(&self) -> bool { - self.get_action().takes_values() + self.get_num_args() + .unwrap_or_else(|| 1.into()) + .takes_values() } /// Report whether [`Arg::allow_hyphen_values`] is set diff --git a/clap_builder/src/builder/debug_asserts.rs b/clap_builder/src/builder/debug_asserts.rs index b7957b83fa4..bfb491f5475 100644 --- a/clap_builder/src/builder/debug_asserts.rs +++ b/clap_builder/src/builder/debug_asserts.rs @@ -704,13 +704,14 @@ fn assert_arg(arg: &Arg) { arg.get_id(), ); - assert_eq!( - arg.get_action().takes_values(), - arg.is_takes_value_set(), - "Argument `{}`'s selected action {:?} contradicts `takes_value`", - arg.get_id(), - arg.get_action() - ); + if arg.is_takes_value_set() { + assert!( + arg.get_action().takes_values(), + "Argument `{}`'s selected action {:?} contradicts `takes_value`", + arg.get_id(), + arg.get_action() + ); + } if let Some(action_type_id) = arg.get_action().value_type_id() { assert_eq!( action_type_id, diff --git a/clap_mangen/src/render.rs b/clap_mangen/src/render.rs index ef4981d80d6..11b8c5dec41 100644 --- a/clap_mangen/src/render.rs +++ b/clap_mangen/src/render.rs @@ -99,7 +99,7 @@ pub(crate) fn options(roff: &mut Roff, cmd: &clap::Command) { (None, None) => vec![], }; - if opt.get_action().takes_values() { + if opt.get_num_args().expect("built").takes_values() { if let Some(value) = &opt.get_value_names() { header.push(roman("=")); header.push(italic(value.join(" "))); @@ -288,7 +288,7 @@ fn option_environment(opt: &clap::Arg) -> Option> { } fn option_default_values(opt: &clap::Arg) -> Option { - if opt.is_hide_default_value_set() || !opt.get_action().takes_values() { + if opt.is_hide_default_value_set() || !opt.get_num_args().expect("built").takes_values() { return None; } else if !opt.get_default_values().is_empty() { let values = opt diff --git a/examples/find.md b/examples/find.md index 75bc3a4f13b..c52cbd391ce 100644 --- a/examples/find.md +++ b/examples/find.md @@ -11,15 +11,13 @@ Options: -V, --version Print version TESTS: - --empty [] File is empty and is either a regular file or a directory [default: false] - [possible values: true, false] - --name Base of file name (the path with the leading directories removed) matches - shell pattern pattern + --empty File is empty and is either a regular file or a directory + --name Base of file name (the path with the leading directories removed) matches shell + pattern pattern OPERATORS: - -o, --or [] expr2 is not evaluate if exp1 is true [default: false] [possible values: true, - false] - -a, --and [] Same as `expr1 expr1` [default: false] [possible values: true, false] + -o, --or expr2 is not evaluate if exp1 is true + -a, --and Same as `expr1 expr1` $ find --empty -o --name .keep [