From 63ca54370964c05896d1fd5d566056fa84a6cb6b Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 30 Mar 2023 02:18:00 -0500 Subject: [PATCH] style: Move away from banned fns --- clap_builder/src/parser/arg_matcher.rs | 4 +++- clap_builder/src/parser/parser.rs | 25 +++++++++++++------------ clap_builder/src/parser/validator.rs | 10 ++++++++-- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/clap_builder/src/parser/arg_matcher.rs b/clap_builder/src/parser/arg_matcher.rs index d584689cdbc2..30fdab1f9a61 100644 --- a/clap_builder/src/parser/arg_matcher.rs +++ b/clap_builder/src/parser/arg_matcher.rs @@ -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) { diff --git a/clap_builder/src/parser/parser.rs b/clap_builder/src/parser/parser.rs index c2910048528d..70e04954e0ad 100644 --- a/clap_builder/src/parser/parser.rs +++ b/clap_builder/src/parser/parser.rs @@ -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(); diff --git a/clap_builder/src/parser/validator.rs b/clap_builder/src/parser/validator.rs index 49d28a34f8cf..5c3d34643ece 100644 --- a/clap_builder/src/parser/validator.rs +++ b/clap_builder/src/parser/validator.rs @@ -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)