mirror of
https://github.com/clap-rs/clap
synced 2024-12-12 22:02:35 +00:00
style: Move away from banned fns
This commit is contained in:
parent
d3d45e8344
commit
feddd124b0
5 changed files with 26 additions and 17 deletions
|
@ -130,7 +130,9 @@ impl ArgMatcher {
|
|||
}
|
||||
|
||||
pub(crate) fn check_explicit(&self, arg: &Id, predicate: &ArgPredicate) -> bool {
|
||||
self.get(arg).map_or(false, |a| a.check_explicit(predicate))
|
||||
self.get(arg)
|
||||
.map(|a| a.check_explicit(predicate))
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
pub(crate) fn start_custom_arg(&mut self, arg: &Arg, source: ValueSource) {
|
||||
|
|
|
@ -305,7 +305,8 @@ impl<'cmd> Parser<'cmd> {
|
|||
.cmd
|
||||
.get_positionals()
|
||||
.last()
|
||||
.map_or(false, |p_name| !p_name.is_last_set());
|
||||
.map(|p_name| !p_name.is_last_set())
|
||||
.unwrap_or_default();
|
||||
|
||||
let missing_pos = self.cmd.is_allow_missing_positional_set()
|
||||
&& is_second_to_last
|
||||
|
@ -779,9 +780,10 @@ impl<'cmd> Parser<'cmd> {
|
|||
matcher.check_explicit(arg_id, &crate::builder::ArgPredicate::IsPresent)
|
||||
})
|
||||
.filter(|&n| {
|
||||
self.cmd.find(n).map_or(true, |a| {
|
||||
!(a.is_hide_set() || required.contains(a.get_id()))
|
||||
})
|
||||
self.cmd
|
||||
.find(n)
|
||||
.map(|a| !(a.is_hide_set() || required.contains(a.get_id())))
|
||||
.unwrap_or(true)
|
||||
})
|
||||
.cloned()
|
||||
.collect();
|
||||
|
@ -810,9 +812,8 @@ impl<'cmd> Parser<'cmd> {
|
|||
.cmd
|
||||
.get_keymap()
|
||||
.get(&pos_counter)
|
||||
.map_or(false, |arg| {
|
||||
arg.is_allow_hyphen_values_set() && !arg.is_last_set()
|
||||
})
|
||||
.map(|arg| arg.is_allow_hyphen_values_set() && !arg.is_last_set())
|
||||
.unwrap_or_default()
|
||||
{
|
||||
debug!(
|
||||
"Parser::parse_long_args: positional at {} allows hyphens",
|
||||
|
@ -847,7 +848,8 @@ impl<'cmd> Parser<'cmd> {
|
|||
.cmd
|
||||
.get_keymap()
|
||||
.get(&pos_counter)
|
||||
.map_or(false, |arg| arg.is_allow_negative_numbers_set())
|
||||
.map(|arg| arg.is_allow_negative_numbers_set())
|
||||
.unwrap_or_default()
|
||||
&& short_arg.is_number()
|
||||
{
|
||||
debug!("Parser::parse_short_arg: negative number");
|
||||
|
@ -856,9 +858,8 @@ impl<'cmd> Parser<'cmd> {
|
|||
.cmd
|
||||
.get_keymap()
|
||||
.get(&pos_counter)
|
||||
.map_or(false, |arg| {
|
||||
arg.is_allow_hyphen_values_set() && !arg.is_last_set()
|
||||
})
|
||||
.map(|arg| arg.is_allow_hyphen_values_set() && !arg.is_last_set())
|
||||
.unwrap_or_default()
|
||||
&& short_arg
|
||||
.clone()
|
||||
.any(|c| !c.map(|c| self.cmd.contains_short(c)).unwrap_or_default())
|
||||
|
@ -1536,7 +1537,7 @@ impl<'cmd> Parser<'cmd> {
|
|||
.filter(|arg_id| {
|
||||
matcher.check_explicit(arg_id, &crate::builder::ArgPredicate::IsPresent)
|
||||
})
|
||||
.filter(|n| self.cmd.find(n).map_or(true, |a| !a.is_hide_set()))
|
||||
.filter(|n| self.cmd.find(n).map(|a| !a.is_hide_set()).unwrap_or(true))
|
||||
.cloned()
|
||||
.collect();
|
||||
|
||||
|
|
|
@ -199,7 +199,10 @@ impl<'cmd> Validator<'cmd> {
|
|||
.map(|(n, _)| n)
|
||||
.filter(|n| {
|
||||
// Filter out the args we don't want to specify.
|
||||
self.cmd.find(n).map_or(false, |a| !a.is_hide_set())
|
||||
self.cmd
|
||||
.find(n)
|
||||
.map(|a| !a.is_hide_set())
|
||||
.unwrap_or_default()
|
||||
})
|
||||
.filter(|key| !conflicting_keys.contains(key))
|
||||
.cloned()
|
||||
|
@ -445,7 +448,10 @@ impl<'cmd> Validator<'cmd> {
|
|||
.map(|(n, _)| n)
|
||||
.filter(|n| {
|
||||
// Filter out the args we don't want to specify.
|
||||
self.cmd.find(n).map_or(false, |a| !a.is_hide_set())
|
||||
self.cmd
|
||||
.find(n)
|
||||
.map(|a| !a.is_hide_set())
|
||||
.unwrap_or_default()
|
||||
})
|
||||
.cloned()
|
||||
.chain(raw_req_args)
|
||||
|
|
|
@ -672,7 +672,8 @@ fn write_positionals_of(p: &Command) -> String {
|
|||
help = arg
|
||||
.get_help()
|
||||
.map(|s| s.to_string())
|
||||
.map_or("".to_owned(), |v| " -- ".to_owned() + &v)
|
||||
.map(|v| " -- ".to_owned() + &v)
|
||||
.unwrap_or_else(|| "".to_owned())
|
||||
.replace('[', "\\[")
|
||||
.replace(']', "\\]")
|
||||
.replace('\'', "'\\''")
|
||||
|
|
|
@ -1297,7 +1297,6 @@ fn low_index_positional_with_extra_flags() {
|
|||
assert_eq!(
|
||||
m.get_many::<String>("input")
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.map(String::from)
|
||||
.collect::<Vec<_>>(),
|
||||
vec![
|
||||
|
|
Loading…
Reference in a new issue