mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 14:22:34 +00:00
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:
parent
52ec1f92e9
commit
6e1ca59ec1
5 changed files with 21 additions and 14 deletions
|
@ -121,14 +121,14 @@ pub fn longs_and_visible_aliases(p: &Command) -> Vec<String> {
|
||||||
pub fn flags<'help>(p: &Command<'help>) -> Vec<Arg<'help>> {
|
pub fn flags<'help>(p: &Command<'help>) -> Vec<Arg<'help>> {
|
||||||
debug!("flags: name={}", p.get_name());
|
debug!("flags: name={}", p.get_name());
|
||||||
p.get_arguments()
|
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()
|
.cloned()
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the possible values for completion
|
/// Get the possible values for completion
|
||||||
pub fn possible_values<'help>(a: &Arg<'help>) -> Option<Vec<clap::builder::PossibleValue<'help>>> {
|
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
|
None
|
||||||
} else {
|
} else {
|
||||||
a.get_value_parser()
|
a.get_value_parser()
|
||||||
|
|
|
@ -148,7 +148,7 @@ fn gen_fish_inner(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn value_completion(option: &Arg) -> String {
|
fn value_completion(option: &Arg) -> String {
|
||||||
if !option.is_takes_value_set() {
|
if !option.get_num_args().expect("built").takes_values() {
|
||||||
return "".to_string();
|
return "".to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -321,7 +321,7 @@ fn gen_options(cmd: &Command, indent: usize) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gen_args(arg: &Arg, 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();
|
return "".to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3795,8 +3795,7 @@ impl<'help> Arg<'help> {
|
||||||
self.is_set(ArgSettings::MultipleValues)
|
self.is_set(ArgSettings::MultipleValues)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Report whether [`Arg::is_takes_value_set`] is set
|
pub(crate) fn is_takes_value_set(&self) -> bool {
|
||||||
pub fn is_takes_value_set(&self) -> bool {
|
|
||||||
self.is_set(ArgSettings::TakesValue)
|
self.is_set(ArgSettings::TakesValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -403,14 +403,22 @@ macro_rules! arg_impl {
|
||||||
$crate::arg_impl! {
|
$crate::arg_impl! {
|
||||||
@arg
|
@arg
|
||||||
({
|
({
|
||||||
if $arg.get_long().is_none() && $arg.get_short().is_none() {
|
match $arg.get_action() {
|
||||||
$arg.num_args(1..)
|
$crate::ArgAction::Set => {
|
||||||
// Allow collecting arguments interleaved with flags
|
if $arg.get_long().is_none() && $arg.get_short().is_none() {
|
||||||
.action($crate::ArgAction::Append)
|
$arg.num_args(1..)
|
||||||
} else if $arg.is_takes_value_set() {
|
// Allow collecting arguments interleaved with flags
|
||||||
$arg.action($crate::ArgAction::Append)
|
.action($crate::ArgAction::Append)
|
||||||
} else {
|
} else {
|
||||||
$arg.action($crate::ArgAction::Count)
|
$arg.action($crate::ArgAction::Append)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
$crate::ArgAction::SetTrue => {
|
||||||
|
$arg.action($crate::ArgAction::Count)
|
||||||
|
}
|
||||||
|
action => {
|
||||||
|
panic!("Unexpected action {:?}", action)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
$($tail)*
|
$($tail)*
|
||||||
|
|
Loading…
Reference in a new issue