style: Move away from banned fns

This commit is contained in:
Ed Page 2023-03-30 02:18:00 -05:00
parent d3d45e8344
commit feddd124b0
5 changed files with 26 additions and 17 deletions

View file

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

View file

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

View file

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

View file

@ -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('\'', "'\\''")

View file

@ -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![