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 feddd12
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
4 changes: 3 additions & 1 deletion clap_builder/src/parser/arg_matcher.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
3 changes: 2 additions & 1 deletion clap_complete/src/shells/zsh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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('\'', "'\\''")
Expand Down
1 change: 0 additions & 1 deletion tests/builder/multiple_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![
Expand Down

0 comments on commit feddd12

Please sign in to comment.