fix!: Make is_takes_value_set private

At this point, it is an implementation detail to help with book keeping
within the builder.
This commit is contained in:
Ed Page 2022-08-04 14:44:11 -05:00
parent 52ec1f92e9
commit 6e1ca59ec1
5 changed files with 21 additions and 14 deletions

View file

@ -121,14 +121,14 @@ pub fn longs_and_visible_aliases(p: &Command) -> Vec<String> {
pub fn flags<'help>(p: &Command<'help>) -> Vec<Arg<'help>> {
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<Vec<clap::builder::PossibleValue<'help>>> {
if !a.is_takes_value_set() {
if !a.get_num_args().expect("built").takes_values() {
None
} else {
a.get_value_parser()

View file

@ -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();
}

View file

@ -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();
}

View file

@ -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)
}

View file

@ -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)*