Skip to content

Commit

Permalink
fix(help): Correctly show help for fake flags
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jan 8, 2024
1 parent d63106b commit 3eaf1af
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
4 changes: 3 additions & 1 deletion clap_builder/src/builder/arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions clap_builder/src/builder/debug_asserts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions clap_mangen/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(" ")));
Expand Down Expand Up @@ -288,7 +288,7 @@ fn option_environment(opt: &clap::Arg) -> Option<Vec<Inline>> {
}

fn option_default_values(opt: &clap::Arg) -> Option<String> {
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
Expand Down
12 changes: 5 additions & 7 deletions examples/find.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ Options:
-V, --version Print version

TESTS:
--empty [<empty>] File is empty and is either a regular file or a directory [default: false]
[possible values: true, false]
--name <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 <name> Base of file name (the path with the leading directories removed) matches shell
pattern pattern

OPERATORS:
-o, --or [<or>] expr2 is not evaluate if exp1 is true [default: false] [possible values: true,
false]
-a, --and [<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
[
Expand Down

0 comments on commit 3eaf1af

Please sign in to comment.