diff --git a/clap_complete/src/generator/utils.rs b/clap_complete/src/generator/utils.rs index 51a68c6e..27bf8078 100644 --- a/clap_complete/src/generator/utils.rs +++ b/clap_complete/src/generator/utils.rs @@ -121,14 +121,14 @@ pub fn longs_and_visible_aliases(p: &Command) -> Vec { pub fn flags<'help>(p: &Command<'help>) -> Vec> { debug!("flags: name={}", p.get_name()); p.get_arguments() - .filter(|a| !a.is_takes_value_set() && !a.is_positional()) + .filter(|a| !a.get_num_args().expect("built").takes_values() && !a.is_positional()) .cloned() .collect() } /// Get the possible values for completion pub fn possible_values<'help>(a: &Arg<'help>) -> Option>> { - if !a.is_takes_value_set() { + if !a.get_num_args().expect("built").takes_values() { None } else { a.get_value_parser() diff --git a/clap_complete/src/shells/fish.rs b/clap_complete/src/shells/fish.rs index eb1e44b5..2550a229 100644 --- a/clap_complete/src/shells/fish.rs +++ b/clap_complete/src/shells/fish.rs @@ -148,7 +148,7 @@ fn gen_fish_inner( } fn value_completion(option: &Arg) -> String { - if !option.is_takes_value_set() { + if !option.get_num_args().expect("built").takes_values() { return "".to_string(); } diff --git a/clap_complete_fig/src/fig.rs b/clap_complete_fig/src/fig.rs index 32e426aa..f7648df7 100644 --- a/clap_complete_fig/src/fig.rs +++ b/clap_complete_fig/src/fig.rs @@ -321,7 +321,7 @@ fn gen_options(cmd: &Command, indent: usize) -> String { } fn gen_args(arg: &Arg, indent: usize) -> String { - if !arg.is_takes_value_set() { + if !arg.get_num_args().expect("built").takes_values() { return "".to_string(); } diff --git a/src/builder/arg.rs b/src/builder/arg.rs index bfb68da1..dcce85ff 100644 --- a/src/builder/arg.rs +++ b/src/builder/arg.rs @@ -3795,8 +3795,7 @@ impl<'help> Arg<'help> { self.is_set(ArgSettings::MultipleValues) } - /// Report whether [`Arg::is_takes_value_set`] is set - pub fn is_takes_value_set(&self) -> bool { + pub(crate) fn is_takes_value_set(&self) -> bool { self.is_set(ArgSettings::TakesValue) } diff --git a/src/macros.rs b/src/macros.rs index 30463cae..423288ca 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -403,14 +403,22 @@ macro_rules! arg_impl { $crate::arg_impl! { @arg ({ - if $arg.get_long().is_none() && $arg.get_short().is_none() { - $arg.num_args(1..) - // Allow collecting arguments interleaved with flags - .action($crate::ArgAction::Append) - } else if $arg.is_takes_value_set() { - $arg.action($crate::ArgAction::Append) - } else { - $arg.action($crate::ArgAction::Count) + match $arg.get_action() { + $crate::ArgAction::Set => { + if $arg.get_long().is_none() && $arg.get_short().is_none() { + $arg.num_args(1..) + // Allow collecting arguments interleaved with flags + .action($crate::ArgAction::Append) + } else { + $arg.action($crate::ArgAction::Append) + } + }, + $crate::ArgAction::SetTrue => { + $arg.action($crate::ArgAction::Count) + } + action => { + panic!("Unexpected action {:?}", action) + } } }) $($tail)*