Skip to content

Commit

Permalink
style: Move away from banned fns
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Mar 30, 2023
1 parent d3d45e8 commit 63ca543
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
4 changes: 3 additions & 1 deletion clap_builder/src/parser/arg_matcher.rs
Expand Up @@ -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) {
Expand Down
25 changes: 13 additions & 12 deletions clap_builder/src/parser/parser.rs
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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");
Expand All @@ -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())
Expand Down Expand Up @@ -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();

Expand Down
10 changes: 8 additions & 2 deletions clap_builder/src/parser/validator.rs
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 63ca543

Please sign in to comment.