diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:31 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:31 +0000 |
commit | dc0db358abe19481e475e10c32149b53370f1a1c (patch) | |
tree | ab8ce99c4b255ce46f99ef402c27916055b899ee /vendor/clap_builder/src/parser | |
parent | Releasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff) | |
download | rustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip |
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/clap_builder/src/parser')
-rw-r--r-- | vendor/clap_builder/src/parser/arg_matcher.rs | 22 | ||||
-rw-r--r-- | vendor/clap_builder/src/parser/matches/arg_matches.rs | 115 | ||||
-rw-r--r-- | vendor/clap_builder/src/parser/parser.rs | 132 | ||||
-rw-r--r-- | vendor/clap_builder/src/parser/validator.rs | 40 |
4 files changed, 172 insertions, 137 deletions
diff --git a/vendor/clap_builder/src/parser/arg_matcher.rs b/vendor/clap_builder/src/parser/arg_matcher.rs index 124d46f5f..b8d827a5b 100644 --- a/vendor/clap_builder/src/parser/arg_matcher.rs +++ b/vendor/clap_builder/src/parser/arg_matcher.rs @@ -45,10 +45,7 @@ impl ArgMatcher { } pub(crate) fn propagate_globals(&mut self, global_arg_vec: &[Id]) { - debug!( - "ArgMatcher::get_global_values: global_arg_vec={:?}", - global_arg_vec - ); + debug!("ArgMatcher::get_global_values: global_arg_vec={global_arg_vec:?}"); let mut vals_map = FlatMap::new(); self.fill_in_global_values(global_arg_vec, &mut vals_map); } @@ -137,10 +134,7 @@ impl ArgMatcher { pub(crate) fn start_custom_arg(&mut self, arg: &Arg, source: ValueSource) { let id = arg.get_id().clone(); - debug!( - "ArgMatcher::start_custom_arg: id={:?}, source={:?}", - id, source - ); + debug!("ArgMatcher::start_custom_arg: id={id:?}, source={source:?}"); let ma = self.entry(id).or_insert(MatchedArg::new_arg(arg)); debug_assert_eq!(ma.type_id(), Some(arg.get_value_parser().type_id())); ma.set_source(source); @@ -148,10 +142,7 @@ impl ArgMatcher { } pub(crate) fn start_custom_group(&mut self, id: Id, source: ValueSource) { - debug!( - "ArgMatcher::start_custom_arg: id={:?}, source={:?}", - id, source - ); + debug!("ArgMatcher::start_custom_arg: id={id:?}, source={source:?}"); let ma = self.entry(id).or_insert(MatchedArg::new_group()); debug_assert_eq!(ma.type_id(), None); ma.set_source(source); @@ -160,7 +151,7 @@ impl ArgMatcher { pub(crate) fn start_occurrence_of_external(&mut self, cmd: &crate::Command) { let id = Id::from_static_ref(Id::EXTERNAL); - debug!("ArgMatcher::start_occurrence_of_external: id={:?}", id,); + debug!("ArgMatcher::start_occurrence_of_external: id={id:?}"); let ma = self.entry(id).or_insert(MatchedArg::new_external(cmd)); debug_assert_eq!( ma.type_id(), @@ -196,10 +187,7 @@ impl ArgMatcher { num_pending ); let expected = o.get_num_args().expect(INTERNAL_ERROR_MSG); - debug!( - "ArgMatcher::needs_more_vals: expected={}, actual={}", - expected, num_pending - ); + debug!("ArgMatcher::needs_more_vals: expected={expected}, actual={num_pending}"); expected.accepts_more(num_pending) } diff --git a/vendor/clap_builder/src/parser/matches/arg_matches.rs b/vendor/clap_builder/src/parser/matches/arg_matches.rs index da8a34783..525904291 100644 --- a/vendor/clap_builder/src/parser/matches/arg_matches.rs +++ b/vendor/clap_builder/src/parser/matches/arg_matches.rs @@ -43,7 +43,7 @@ use crate::INTERNAL_ERROR_MSG; /// // to get information about the "cfg" argument we created, such as the value supplied we use /// // various ArgMatches methods, such as [ArgMatches::get_one] /// if let Some(c) = matches.get_one::<String>("cfg") { -/// println!("Value for -c: {}", c); +/// println!("Value for -c: {c}"); /// } /// /// // The ArgMatches::get_one method returns an Option because the user may not have supplied @@ -143,10 +143,7 @@ impl ArgMatches { #[cfg_attr(debug_assertions, track_caller)] pub fn get_count(&self, id: &str) -> u8 { *self.get_one::<u8>(id).unwrap_or_else(|| { - panic!( - "arg `{}`'s `ArgAction` should be `Count` which should provide a default", - id - ) + panic!("arg `{id}`'s `ArgAction` should be `Count` which should provide a default") }) } @@ -182,8 +179,7 @@ impl ArgMatches { .get_one::<bool>(id) .unwrap_or_else(|| { panic!( - "arg `{}`'s `ArgAction` should be one of `SetTrue`, `SetFalse` which should provide a default", - id + "arg `{id}`'s `ArgAction` should be one of `SetTrue`, `SetFalse` which should provide a default" ) }) } @@ -928,7 +924,7 @@ impl ArgMatches { /// ("clone", sub_m) => {}, // clone was used /// ("push", sub_m) => {}, // push was used /// ("commit", sub_m) => {}, // commit was used - /// (name, _) => unimplemented!("{}", name), + /// (name, _) => unimplemented!("{name}"), /// } /// ``` /// @@ -1405,7 +1401,12 @@ impl<T> Iterator for Values<T> { type Item = T; fn next(&mut self) -> Option<Self::Item> { - self.iter.next() + if let Some(next) = self.iter.next() { + self.len -= 1; + Some(next) + } else { + None + } } fn size_hint(&self) -> (usize, Option<usize>) { (self.len, Some(self.len)) @@ -1414,7 +1415,12 @@ impl<T> Iterator for Values<T> { impl<T> DoubleEndedIterator for Values<T> { fn next_back(&mut self) -> Option<Self::Item> { - self.iter.next_back() + if let Some(next) = self.iter.next_back() { + self.len -= 1; + Some(next) + } else { + None + } } } @@ -1463,7 +1469,12 @@ impl<'a, T: 'a> Iterator for ValuesRef<'a, T> { type Item = &'a T; fn next(&mut self) -> Option<Self::Item> { - self.iter.next() + if let Some(next) = self.iter.next() { + self.len -= 1; + Some(next) + } else { + None + } } fn size_hint(&self) -> (usize, Option<usize>) { (self.len, Some(self.len)) @@ -1472,7 +1483,12 @@ impl<'a, T: 'a> Iterator for ValuesRef<'a, T> { impl<'a, T: 'a> DoubleEndedIterator for ValuesRef<'a, T> { fn next_back(&mut self) -> Option<Self::Item> { - self.iter.next_back() + if let Some(next) = self.iter.next_back() { + self.len -= 1; + Some(next) + } else { + None + } } } @@ -1526,7 +1542,12 @@ impl<'a> Iterator for RawValues<'a> { type Item = &'a OsStr; fn next(&mut self) -> Option<&'a OsStr> { - self.iter.next() + if let Some(next) = self.iter.next() { + self.len -= 1; + Some(next) + } else { + None + } } fn size_hint(&self) -> (usize, Option<usize>) { (self.len, Some(self.len)) @@ -1535,7 +1556,12 @@ impl<'a> Iterator for RawValues<'a> { impl<'a> DoubleEndedIterator for RawValues<'a> { fn next_back(&mut self) -> Option<&'a OsStr> { - self.iter.next_back() + if let Some(next) = self.iter.next_back() { + self.len -= 1; + Some(next) + } else { + None + } } } @@ -1570,7 +1596,12 @@ impl<'a> Iterator for GroupedValues<'a> { type Item = Vec<&'a str>; fn next(&mut self) -> Option<Self::Item> { - self.iter.next() + if let Some(next) = self.iter.next() { + self.len -= 1; + Some(next) + } else { + None + } } fn size_hint(&self) -> (usize, Option<usize>) { (self.len, Some(self.len)) @@ -1580,7 +1611,12 @@ impl<'a> Iterator for GroupedValues<'a> { #[allow(deprecated)] impl<'a> DoubleEndedIterator for GroupedValues<'a> { fn next_back(&mut self) -> Option<Self::Item> { - self.iter.next_back() + if let Some(next) = self.iter.next_back() { + self.len -= 1; + Some(next) + } else { + None + } } } @@ -1830,7 +1866,12 @@ impl<'a> Iterator for Indices<'a> { type Item = usize; fn next(&mut self) -> Option<usize> { - self.iter.next() + if let Some(next) = self.iter.next() { + self.len -= 1; + Some(next) + } else { + None + } } fn size_hint(&self) -> (usize, Option<usize>) { (self.len, Some(self.len)) @@ -1839,7 +1880,12 @@ impl<'a> Iterator for Indices<'a> { impl<'a> DoubleEndedIterator for Indices<'a> { fn next_back(&mut self) -> Option<usize> { - self.iter.next_back() + if let Some(next) = self.iter.next_back() { + self.len -= 1; + Some(next) + } else { + None + } } } @@ -1948,4 +1994,37 @@ mod tests { .len(); assert_eq!(l, 1); } + + #[test] + fn rev_iter() { + let mut matches = crate::Command::new("myprog") + .arg(crate::Arg::new("a").short('a').action(ArgAction::Append)) + .arg(crate::Arg::new("b").short('b').action(ArgAction::Append)) + .try_get_matches_from(vec!["myprog", "-a1", "-b1", "-b3"]) + .unwrap(); + + let a_index = matches + .indices_of("a") + .expect("missing aopt indices") + .collect::<Vec<_>>(); + dbg!(&a_index); + let a_value = matches + .remove_many::<String>("a") + .expect("missing aopt values"); + dbg!(&a_value); + let a = a_index.into_iter().zip(a_value).rev().collect::<Vec<_>>(); + dbg!(a); + + let b_index = matches + .indices_of("b") + .expect("missing aopt indices") + .collect::<Vec<_>>(); + dbg!(&b_index); + let b_value = matches + .remove_many::<String>("b") + .expect("missing aopt values"); + dbg!(&b_value); + let b = b_index.into_iter().zip(b_value).rev().collect::<Vec<_>>(); + dbg!(b); + } } diff --git a/vendor/clap_builder/src/parser/parser.rs b/vendor/clap_builder/src/parser/parser.rs index 723e1cd69..d2e198b28 100644 --- a/vendor/clap_builder/src/parser/parser.rs +++ b/vendor/clap_builder/src/parser/parser.rs @@ -88,7 +88,7 @@ impl<'cmd> Parser<'cmd> { { // Does the arg match a subcommand name, or any of its aliases (if defined) let sc_name = self.possible_subcommand(arg_os.to_value(), valid_arg_found); - debug!("Parser::get_matches_with: sc={:?}", sc_name); + debug!("Parser::get_matches_with: sc={sc_name:?}"); if let Some(sc_name) = sc_name { if sc_name == "help" && !self.cmd.is_disable_help_subcommand_set() { ok!(self.parse_help_subcommand(raw_args.remaining(&mut args_cursor))); @@ -120,10 +120,7 @@ impl<'cmd> Parser<'cmd> { pos_counter, &mut valid_arg_found, )); - debug!( - "Parser::get_matches_with: After parse_long_arg {:?}", - parse_result - ); + debug!("Parser::get_matches_with: After parse_long_arg {parse_result:?}"); match parse_result { ParseResult::NoArg => { unreachable!("`to_long` always has the flag specified") @@ -193,10 +190,7 @@ impl<'cmd> Parser<'cmd> { &mut valid_arg_found, )); // If it's None, we then check if one of those two AppSettings was set - debug!( - "Parser::get_matches_with: After parse_short_arg {:?}", - parse_result - ); + debug!("Parser::get_matches_with: After parse_short_arg {parse_result:?}"); match parse_result { ParseResult::NoArg => { // Is a single dash `-`, try positional. @@ -312,14 +306,8 @@ impl<'cmd> Parser<'cmd> { && is_second_to_last && !trailing_values; - debug!( - "Parser::get_matches_with: Positional counter...{}", - pos_counter - ); - debug!( - "Parser::get_matches_with: Low index multiples...{:?}", - low_index_mults - ); + debug!("Parser::get_matches_with: Positional counter...{pos_counter}"); + debug!("Parser::get_matches_with: Low index multiples...{low_index_mults:?}"); if low_index_mults || missing_pos { let skip_current = if let Some(n) = raw_args.peek(&args_cursor) { @@ -384,27 +372,27 @@ impl<'cmd> Parser<'cmd> { if matcher.pending_arg_id() != Some(arg.get_id()) || !arg.is_multiple_values_set() { ok!(self.resolve_pending(matcher)); } - if let Some(_parse_result) = self.check_terminator(arg, arg_os.to_value_os()) { - debug!( - "Parser::get_matches_with: ignoring terminator result {:?}", - _parse_result - ); - } else { - let arg_values = matcher.pending_values_mut( - arg.get_id(), - Some(Identifier::Index), - trailing_values, - ); - arg_values.push(arg_os.to_value_os().to_owned()); - } + parse_state = + if let Some(parse_result) = self.check_terminator(arg, arg_os.to_value_os()) { + debug_assert_eq!(parse_result, ParseResult::ValuesDone); + pos_counter += 1; + ParseState::ValuesDone + } else { + let arg_values = matcher.pending_values_mut( + arg.get_id(), + Some(Identifier::Index), + trailing_values, + ); + arg_values.push(arg_os.to_value_os().to_owned()); - // Only increment the positional counter if it doesn't allow multiples - if !arg.is_multiple() { - pos_counter += 1; - parse_state = ParseState::ValuesDone; - } else { - parse_state = ParseState::Pos(arg.get_id().clone()); - } + // Only increment the positional counter if it doesn't allow multiples + if !arg.is_multiple() { + pos_counter += 1; + ParseState::ValuesDone + } else { + ParseState::Pos(arg.get_id().clone()) + } + }; valid_arg_found = true; } else if let Some(external_parser) = self.cmd.get_external_subcommand_value_parser().cloned() @@ -535,7 +523,7 @@ impl<'cmd> Parser<'cmd> { arg: Result<&str, &OsStr>, valid_arg_found: bool, ) -> Option<&str> { - debug!("Parser::possible_subcommand: arg={:?}", arg); + debug!("Parser::possible_subcommand: arg={arg:?}"); let arg = some!(arg.ok()); if !(self.cmd.is_args_conflicts_with_subcommands_set() && valid_arg_found) { @@ -564,7 +552,7 @@ impl<'cmd> Parser<'cmd> { // Checks if the arg matches a long flag subcommand name, or any of its aliases (if defined) fn possible_long_flag_subcommand(&self, arg: &str) -> Option<&str> { - debug!("Parser::possible_long_flag_subcommand: arg={:?}", arg); + debug!("Parser::possible_long_flag_subcommand: arg={arg:?}"); if self.cmd.is_infer_subcommands_set() { let options = self .cmd @@ -687,10 +675,7 @@ impl<'cmd> Parser<'cmd> { } if let Err(error) = p.get_matches_with(&mut sc_matcher, raw_args, args_cursor) { if partial_parsing_enabled { - debug!( - "Parser::parse_subcommand: ignored error in subcommand {}: {:?}", - sc_name, error - ); + debug!("Parser::parse_subcommand: ignored error in subcommand {sc_name}: {error:?}"); } else { return Err(error); } @@ -741,10 +726,10 @@ impl<'cmd> Parser<'cmd> { } let arg = if let Some(arg) = self.cmd.get_keymap().get(long_arg) { - debug!("Parser::parse_long_arg: Found valid arg or flag '{}'", arg); + debug!("Parser::parse_long_arg: Found valid arg or flag '{arg}'"); Some((long_arg, arg)) } else if self.cmd.is_infer_long_args_set() { - self.cmd.get_arguments().find_map(|a| { + let mut iter = self.cmd.get_arguments().filter_map(|a| { if let Some(long) = a.get_long() { if long.starts_with(long_arg) { return Some((long, a)); @@ -753,7 +738,9 @@ impl<'cmd> Parser<'cmd> { a.aliases .iter() .find_map(|(alias, _)| alias.starts_with(long_arg).then(|| (alias.as_str(), a))) - }) + }); + + iter.next().filter(|_| iter.next().is_none()) } else { None }; @@ -770,10 +757,7 @@ impl<'cmd> Parser<'cmd> { self.parse_opt_value(ident, long_value, arg, matcher, has_eq) } else if let Some(rest) = long_value { let required = self.cmd.required_graph(); - debug!( - "Parser::parse_long_arg({:?}): Got invalid literal `{:?}`", - long_arg, rest - ); + debug!("Parser::parse_long_arg({long_arg:?}): Got invalid literal `{rest:?}`"); let mut used: Vec<Id> = matcher .arg_ids() .filter(|arg_id| { @@ -795,7 +779,7 @@ impl<'cmd> Parser<'cmd> { arg: arg.to_string(), }) } else { - debug!("Parser::parse_long_arg({:?}): Presence validated", long_arg); + debug!("Parser::parse_long_arg({long_arg:?}): Presence validated"); let trailing_idx = None; self.react( Some(ident), @@ -815,10 +799,7 @@ impl<'cmd> Parser<'cmd> { .map(|arg| arg.is_allow_hyphen_values_set() && !arg.is_last_set()) .unwrap_or_default() { - debug!( - "Parser::parse_long_args: positional at {} allows hyphens", - pos_counter - ); + debug!("Parser::parse_long_args: positional at {pos_counter} allows hyphens"); Ok(ParseResult::MaybeHyphenValue) } else { Ok(ParseResult::NoMatchingArg { @@ -836,7 +817,7 @@ impl<'cmd> Parser<'cmd> { pos_counter: usize, valid_arg_found: &mut bool, ) -> ClapResult<ParseResult> { - debug!("Parser::parse_short_arg: short_arg={:?}", short_arg); + debug!("Parser::parse_short_arg: short_arg={short_arg:?}"); #[allow(clippy::blocks_in_if_conditions)] if matches!(parse_state, ParseState::Opt(opt) | ParseState::Pos(opt) @@ -864,10 +845,7 @@ impl<'cmd> Parser<'cmd> { .clone() .any(|c| !c.map(|c| self.cmd.contains_short(c)).unwrap_or_default()) { - debug!( - "Parser::parse_short_args: positional at {} allows hyphens", - pos_counter - ); + debug!("Parser::parse_short_args: positional at {pos_counter} allows hyphens"); return Ok(ParseResult::MaybeHyphenValue); } @@ -890,7 +868,7 @@ impl<'cmd> Parser<'cmd> { }); } }; - debug!("Parser::parse_short_arg:iter:{}", c); + debug!("Parser::parse_short_arg:iter:{c}"); // Check for matching short options, and return the name if there is no trailing // concatenated value: -oval @@ -898,10 +876,7 @@ impl<'cmd> Parser<'cmd> { // Value: val if let Some(arg) = self.cmd.get_keymap().get(&c) { let ident = Identifier::Short; - debug!( - "Parser::parse_short_arg:iter:{}: Found valid opt or flag", - c - ); + debug!("Parser::parse_short_arg:iter:{c}: Found valid opt or flag"); *valid_arg_found = true; if !arg.is_takes_value_set() { let arg_values = Vec::new(); @@ -921,10 +896,7 @@ impl<'cmd> Parser<'cmd> { // // Cloning the iterator, so we rollback if it isn't there. let val = short_arg.clone().next_value_os().unwrap_or_default(); - debug!( - "Parser::parse_short_arg:iter:{}: val={:?}, short_arg={:?}", - c, val, short_arg - ); + debug!("Parser::parse_short_arg:iter:{c}: val={val:?}, short_arg={short_arg:?}"); let val = Some(val).filter(|v| !v.is_empty()); // Default to "we're expecting a value later". @@ -946,7 +918,7 @@ impl<'cmd> Parser<'cmd> { } return if let Some(sc_name) = self.cmd.find_short_subcmd(c) { - debug!("Parser::parse_short_arg:iter:{}: subcommand={}", c, sc_name); + debug!("Parser::parse_short_arg:iter:{c}: subcommand={sc_name}"); // Make sure indices get updated before reading `self.cur_idx` ok!(self.resolve_pending(matcher)); self.cur_idx.set(self.cur_idx.get() + 1); @@ -1053,7 +1025,7 @@ impl<'cmd> Parser<'cmd> { raw_vals: Vec<OsString>, matcher: &mut ArgMatcher, ) -> ClapResult<()> { - debug!("Parser::push_arg_values: {:?}", raw_vals); + debug!("Parser::push_arg_values: {raw_vals:?}"); for raw_val in raw_vals { // update the current index because each value is a distinct index to clap @@ -1262,7 +1234,7 @@ impl<'cmd> Parser<'cmd> { Some(Identifier::Index) => true, None => true, }; - debug!("Help: use_long={}", use_long); + debug!("Help: use_long={use_long}"); Err(self.help_err(use_long)) } ArgAction::Version => { @@ -1272,7 +1244,7 @@ impl<'cmd> Parser<'cmd> { Some(Identifier::Index) => true, None => true, }; - debug!("Version: use_long={}", use_long); + debug!("Version: use_long={use_long}"); Err(self.version_err(use_long)) } } @@ -1337,7 +1309,7 @@ impl<'cmd> Parser<'cmd> { fn remove_overrides(&self, arg: &Arg, matcher: &mut ArgMatcher) { debug!("Parser::remove_overrides: id={:?}", arg.id); for override_id in &arg.overrides { - debug!("Parser::remove_overrides:iter:{:?}: removing", override_id); + debug!("Parser::remove_overrides:iter:{override_id:?}: removing"); matcher.remove(override_id); } @@ -1351,7 +1323,7 @@ impl<'cmd> Parser<'cmd> { } } for overrider_id in transitive { - debug!("Parser::remove_overrides:iter:{:?}: removing", overrider_id); + debug!("Parser::remove_overrides:iter:{overrider_id:?}: removing"); matcher.remove(overrider_id); } } @@ -1364,13 +1336,13 @@ impl<'cmd> Parser<'cmd> { // Use env only if the arg was absent among command line args, // early return if this is not the case. if matcher.contains(&arg.id) { - debug!("Parser::add_env: Skipping existing arg `{}`", arg); + debug!("Parser::add_env: Skipping existing arg `{arg}`"); continue; } - debug!("Parser::add_env: Checking arg `{}`", arg); + debug!("Parser::add_env: Checking arg `{arg}`"); if let Some((_, Some(ref val))) = arg.env { - debug!("Parser::add_env: Found an opt with value={:?}", val); + debug!("Parser::add_env: Found an opt with value={val:?}"); let arg_values = vec![val.to_owned()]; let trailing_idx = None; let _ = ok!(self.react( @@ -1504,7 +1476,7 @@ impl<'cmd> Parser<'cmd> { remaining_args: &[&OsStr], trailing_values: bool, ) -> ClapError { - debug!("Parser::did_you_mean_error: arg={}", arg); + debug!("Parser::did_you_mean_error: arg={arg}"); // Didn't match a flag or option let longs = self .cmd @@ -1515,7 +1487,7 @@ impl<'cmd> Parser<'cmd> { _ => None, }) .collect::<Vec<_>>(); - debug!("Parser::did_you_mean_error: longs={:?}", longs); + debug!("Parser::did_you_mean_error: longs={longs:?}"); let did_you_mean = suggestions::did_you_mean_flag( arg, diff --git a/vendor/clap_builder/src/parser/validator.rs b/vendor/clap_builder/src/parser/validator.rs index 5c3d34643..17fb7c1e2 100644 --- a/vendor/clap_builder/src/parser/validator.rs +++ b/vendor/clap_builder/src/parser/validator.rs @@ -31,7 +31,7 @@ impl<'cmd> Validator<'cmd> { let has_subcmd = matcher.subcommand_name().is_some(); if let ParseState::Opt(a) = parse_state { - debug!("Validator::validate: needs_val_of={:?}", a); + debug!("Validator::validate: needs_val_of={a:?}"); let o = &self.cmd[&a]; let should_err = if let Some(v) = matcher.args.get(o.get_id()) { @@ -102,7 +102,7 @@ impl<'cmd> Validator<'cmd> { .filter(|(_, matched)| matched.check_explicit(&ArgPredicate::IsPresent)) .filter(|(arg_id, _)| self.cmd.find(arg_id).is_some()) { - debug!("Validator::validate_conflicts::iter: id={:?}", arg_id); + debug!("Validator::validate_conflicts::iter: id={arg_id:?}"); let conflicts = conflicts.gather_conflicts(self.cmd, arg_id); ok!(self.build_conflict_err(arg_id, &conflicts, matcher)); } @@ -130,14 +130,15 @@ impl<'cmd> Validator<'cmd> { .args() .filter(|(_, matched)| matched.check_explicit(&crate::builder::ArgPredicate::IsPresent)) .filter_map(|(id, _)| { - debug!("Validator::validate_exclusive:iter:{:?}", id); + debug!("Validator::validate_exclusive:iter:{id:?}"); self.cmd .find(id) // Find `arg`s which are exclusive but also appear with other args. .filter(|&arg| arg.is_exclusive_set() && args_count > 1) }) - // Throw an error for the first conflict found. - .try_for_each(|arg| { + .next() + .map(|arg| { + // Throw an error for the first conflict found. Err(Error::argument_conflict( self.cmd, arg.to_string(), @@ -147,6 +148,7 @@ impl<'cmd> Validator<'cmd> { .create_usage_with_title(&[]), )) }) + .unwrap_or(Ok(())) } fn build_conflict_err( @@ -159,7 +161,7 @@ impl<'cmd> Validator<'cmd> { return Ok(()); } - debug!("Validator::build_conflict_err: name={:?}", name); + debug!("Validator::build_conflict_err: name={name:?}"); let mut seen = FlatSet::new(); let conflicts = conflict_ids .iter() @@ -226,7 +228,7 @@ impl<'cmd> Validator<'cmd> { .args() .filter(|(_, matched)| matched.check_explicit(&ArgPredicate::IsPresent)) { - debug!("Validator::gather_requires:iter:{:?}", name); + debug!("Validator::gather_requires:iter:{name:?}"); if let Some(arg) = self.cmd.find(name) { let is_relevant = |(val, req_arg): &(ArgPredicate, Id)| -> Option<Id> { let required = matched.check_explicit(val); @@ -237,7 +239,7 @@ impl<'cmd> Validator<'cmd> { self.required.insert(req); } } else if let Some(g) = self.cmd.find_group(name) { - debug!("Validator::gather_requires:iter:{:?}:group", name); + debug!("Validator::gather_requires:iter:{name:?}:group"); for r in &g.requires { self.required.insert(r.clone()); } @@ -261,17 +263,14 @@ impl<'cmd> Validator<'cmd> { .map(|arg| arg.is_exclusive_set()) .unwrap_or_default() }); - debug!( - "Validator::validate_required: is_exclusive_present={}", - is_exclusive_present - ); + debug!("Validator::validate_required: is_exclusive_present={is_exclusive_present}"); for arg_or_group in self .required .iter() .filter(|r| !matcher.check_explicit(r, &ArgPredicate::IsPresent)) { - debug!("Validator::validate_required:iter:aog={:?}", arg_or_group); + debug!("Validator::validate_required:iter:aog={arg_or_group:?}"); if let Some(arg) = self.cmd.find(arg_or_group) { debug!("Validator::validate_required:iter: This is an arg"); if !is_exclusive_present && !self.is_missing_required_ok(arg, conflicts) { @@ -380,7 +379,7 @@ impl<'cmd> Validator<'cmd> { } for group_id in self.cmd.groups_for_arg(a.get_id()) { if !conflicts.gather_conflicts(self.cmd, &group_id).is_empty() { - debug!("Validator::is_missing_required_ok: true ({})", group_id); + debug!("Validator::is_missing_required_ok: true ({group_id})"); return true; } } @@ -402,7 +401,7 @@ impl<'cmd> Validator<'cmd> { matcher: &ArgMatcher, raw_req_args: Vec<Id>, ) -> ClapResult<()> { - debug!("Validator::missing_required_error; incl={:?}", raw_req_args); + debug!("Validator::missing_required_error; incl={raw_req_args:?}"); debug!( "Validator::missing_required_error: reqs={:?}", self.required @@ -429,7 +428,7 @@ impl<'cmd> Validator<'cmd> { } else if let Some(_group) = self.cmd.find_group(id) { self.cmd.format_group(id).to_string() } else { - debug_assert!(false, "id={:?} is unknown", id); + debug_assert!(false, "id={id:?} is unknown"); "".to_owned() } }) @@ -437,10 +436,7 @@ impl<'cmd> Validator<'cmd> { } }; - debug!( - "Validator::missing_required_error: req_args={:#?}", - req_args - ); + debug!("Validator::missing_required_error: req_args={req_args:#?}"); let used: Vec<Id> = matcher .args() @@ -486,7 +482,7 @@ impl Conflicts { } fn gather_conflicts(&self, cmd: &Command, arg_id: &Id) -> Vec<Id> { - debug!("Conflicts::gather_conflicts: arg={:?}", arg_id); + debug!("Conflicts::gather_conflicts: arg={arg_id:?}"); let mut conflicts = Vec::new(); let arg_id_conflicts_storage; @@ -510,7 +506,7 @@ impl Conflicts { } } - debug!("Conflicts::gather_conflicts: conflicts={:?}", conflicts); + debug!("Conflicts::gather_conflicts: conflicts={conflicts:?}"); conflicts } |