diff options
Diffstat (limited to '')
-rw-r--r-- | vendor/clap-3.2.20/src/parser/arg_matcher.rs (renamed from vendor/clap/src/parser/arg_matcher.rs) | 4 | ||||
-rw-r--r-- | vendor/clap-3.2.20/src/parser/features/mod.rs (renamed from vendor/clap/src/parser/features/mod.rs) | 0 | ||||
-rw-r--r-- | vendor/clap-3.2.20/src/parser/features/suggestions.rs (renamed from vendor/clap/src/parser/features/suggestions.rs) | 0 | ||||
-rw-r--r-- | vendor/clap-3.2.20/src/parser/matches/any_value.rs (renamed from vendor/clap/src/parser/matches/any_value.rs) | 0 | ||||
-rw-r--r-- | vendor/clap-3.2.20/src/parser/matches/arg_matches.rs (renamed from vendor/clap/src/parser/matches/arg_matches.rs) | 74 | ||||
-rw-r--r-- | vendor/clap-3.2.20/src/parser/matches/matched_arg.rs (renamed from vendor/clap/src/parser/matches/matched_arg.rs) | 0 | ||||
-rw-r--r-- | vendor/clap-3.2.20/src/parser/matches/mod.rs (renamed from vendor/clap/src/parser/matches/mod.rs) | 0 | ||||
-rw-r--r-- | vendor/clap-3.2.20/src/parser/matches/value_source.rs (renamed from vendor/clap/src/parser/matches/value_source.rs) | 0 | ||||
-rw-r--r-- | vendor/clap-3.2.20/src/parser/mod.rs (renamed from vendor/clap/src/parser/mod.rs) | 0 | ||||
-rw-r--r-- | vendor/clap-3.2.20/src/parser/parser.rs (renamed from vendor/clap/src/parser/parser.rs) | 148 | ||||
-rw-r--r-- | vendor/clap-3.2.20/src/parser/validator.rs (renamed from vendor/clap/src/parser/validator.rs) | 0 | ||||
-rw-r--r-- | vendor/clap/src/parser/error.rs | 56 |
12 files changed, 147 insertions, 135 deletions
diff --git a/vendor/clap/src/parser/arg_matcher.rs b/vendor/clap-3.2.20/src/parser/arg_matcher.rs index 8d15c5799..22087e722 100644 --- a/vendor/clap/src/parser/arg_matcher.rs +++ b/vendor/clap-3.2.20/src/parser/arg_matcher.rs @@ -74,9 +74,7 @@ impl ArgMatcher { // a default value of `other` myprog would have an existing MatchedArg for // `--global-arg` where the value is `other` let to_update = if let Some(parent_ma) = vals_map.get(global_arg) { - if parent_ma.check_explicit(ArgPredicate::IsPresent) - && !ma.check_explicit(ArgPredicate::IsPresent) - { + if parent_ma.source() > ma.source() { parent_ma } else { ma diff --git a/vendor/clap/src/parser/features/mod.rs b/vendor/clap-3.2.20/src/parser/features/mod.rs index bdeb766ec..bdeb766ec 100644 --- a/vendor/clap/src/parser/features/mod.rs +++ b/vendor/clap-3.2.20/src/parser/features/mod.rs diff --git a/vendor/clap/src/parser/features/suggestions.rs b/vendor/clap-3.2.20/src/parser/features/suggestions.rs index 9e46f3c9e..9e46f3c9e 100644 --- a/vendor/clap/src/parser/features/suggestions.rs +++ b/vendor/clap-3.2.20/src/parser/features/suggestions.rs diff --git a/vendor/clap/src/parser/matches/any_value.rs b/vendor/clap-3.2.20/src/parser/matches/any_value.rs index a9277e75f..a9277e75f 100644 --- a/vendor/clap/src/parser/matches/any_value.rs +++ b/vendor/clap-3.2.20/src/parser/matches/any_value.rs diff --git a/vendor/clap/src/parser/matches/arg_matches.rs b/vendor/clap-3.2.20/src/parser/matches/arg_matches.rs index 17fa63ca6..2585c0219 100644 --- a/vendor/clap/src/parser/matches/arg_matches.rs +++ b/vendor/clap-3.2.20/src/parser/matches/arg_matches.rs @@ -119,6 +119,69 @@ impl ArgMatches { MatchesError::unwrap(&internal_id, self.try_get_one(id)) } + /// Gets the value of a specific [`ArgAction::Count`][crate::ArgAction::Count] flag + /// + /// # Panic + /// + /// If the argument's action is not [`ArgAction::Count`][crate::ArgAction::Count] + /// + /// # Examples + /// + /// ```rust + /// # use clap::Command; + /// # use clap::Arg; + /// let cmd = Command::new("mycmd") + /// .arg( + /// Arg::new("flag") + /// .long("flag") + /// .action(clap::ArgAction::Count) + /// ); + /// + /// let matches = cmd.clone().try_get_matches_from(["mycmd", "--flag", "--flag"]).unwrap(); + /// assert_eq!( + /// matches.get_count("flag"), + /// 2 + /// ); + /// ``` + #[track_caller] + pub fn get_count(&self, id: &str) -> u8 { + *self + .get_one::<u8>(id) + .expect("ArgAction::Count is defaulted") + } + + /// Gets the value of a specific [`ArgAction::SetTrue`][crate::ArgAction::SetTrue] or [`ArgAction::SetFalse`][crate::ArgAction::SetFalse] flag + /// + /// # Panic + /// + /// If the argument's action is not [`ArgAction::SetTrue`][crate::ArgAction::SetTrue] or [`ArgAction::SetFalse`][crate::ArgAction::SetFalse] + /// + /// # Examples + /// + /// ```rust + /// # use clap::Command; + /// # use clap::Arg; + /// let cmd = Command::new("mycmd") + /// .arg( + /// Arg::new("flag") + /// .long("flag") + /// .action(clap::ArgAction::SetTrue) + /// ); + /// + /// let matches = cmd.clone().try_get_matches_from(["mycmd", "--flag", "--flag"]).unwrap(); + /// assert!(matches.contains_id("flag")); + /// assert_eq!( + /// matches.get_flag("flag"), + /// true + /// ); + /// ``` + #[track_caller] + pub fn get_flag(&self, id: &str) -> bool { + *self + .get_one::<bool>(id) + .expect("ArgAction::SetTrue / ArgAction::SetFalse is defaulted") + } + /// Iterate over values of a specific option or positional argument. /// /// i.e. an argument that takes multiple values at runtime. @@ -604,13 +667,13 @@ impl ArgMatches { value.and_then(MatchedArg::source) } - /// Deprecated, replaced with [`ArgAction::Count`][crate::ArgAction] or - /// [`ArgMatches::get_many`]`.len()`. + /// Deprecated, replaced with [`ArgAction::Count`][crate::ArgAction], + /// [`ArgMatches::get_many`]`.len()`, or [`ArgMatches::value_source`]. #[cfg_attr( feature = "deprecated", deprecated( since = "3.2.0", - note = "Replaced with either `ArgAction::Count` or `ArgMatches::get_many(...).len()`" + note = "Replaced with either `ArgAction::Count`, `ArgMatches::get_many(...).len()`, or `ArgMatches::value_source`" ) )] #[cfg_attr(debug_assertions, track_caller)] @@ -1742,6 +1805,11 @@ mod tests { use super::*; #[test] + fn check_auto_traits() { + static_assertions::assert_impl_all!(ArgMatches: Send, Sync, Unpin); + } + + #[test] fn test_default_values() { #![allow(deprecated)] let mut values: Values = Values::default(); diff --git a/vendor/clap/src/parser/matches/matched_arg.rs b/vendor/clap-3.2.20/src/parser/matches/matched_arg.rs index fde6d37f3..fde6d37f3 100644 --- a/vendor/clap/src/parser/matches/matched_arg.rs +++ b/vendor/clap-3.2.20/src/parser/matches/matched_arg.rs diff --git a/vendor/clap/src/parser/matches/mod.rs b/vendor/clap-3.2.20/src/parser/matches/mod.rs index 7b88eeca7..7b88eeca7 100644 --- a/vendor/clap/src/parser/matches/mod.rs +++ b/vendor/clap-3.2.20/src/parser/matches/mod.rs diff --git a/vendor/clap/src/parser/matches/value_source.rs b/vendor/clap-3.2.20/src/parser/matches/value_source.rs index fb762d2af..fb762d2af 100644 --- a/vendor/clap/src/parser/matches/value_source.rs +++ b/vendor/clap-3.2.20/src/parser/matches/value_source.rs diff --git a/vendor/clap/src/parser/mod.rs b/vendor/clap-3.2.20/src/parser/mod.rs index da81648e1..da81648e1 100644 --- a/vendor/clap/src/parser/mod.rs +++ b/vendor/clap-3.2.20/src/parser/mod.rs diff --git a/vendor/clap/src/parser/parser.rs b/vendor/clap-3.2.20/src/parser/parser.rs index fc95dad22..ad2bc6e9c 100644 --- a/vendor/clap/src/parser/parser.rs +++ b/vendor/clap-3.2.20/src/parser/parser.rs @@ -98,77 +98,6 @@ impl<'help, 'cmd> Parser<'help, 'cmd> { arg_os.to_value_os().as_raw_bytes() ); - // Correct pos_counter. - pos_counter = { - let is_second_to_last = pos_counter + 1 == positional_count; - - // The last positional argument, or second to last positional - // argument may be set to .multiple_values(true) or `.multiple_occurrences(true)` - let low_index_mults = is_second_to_last - && self - .cmd - .get_positionals() - .any(|a| a.is_multiple() && (positional_count != a.index.unwrap_or(0))) - && self - .cmd - .get_positionals() - .last() - .map_or(false, |p_name| !p_name.is_last_set()); - - let missing_pos = self.cmd.is_allow_missing_positional_set() - && 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 - ); - - if low_index_mults || missing_pos { - let skip_current = if let Some(n) = raw_args.peek(&args_cursor) { - if let Some(arg) = self - .cmd - .get_positionals() - .find(|a| a.index == Some(pos_counter)) - { - // If next value looks like a new_arg or it's a - // subcommand, skip positional argument under current - // pos_counter(which means current value cannot be a - // positional argument with a value next to it), assume - // current value matches the next arg. - self.is_new_arg(&n, arg) - || self - .possible_subcommand(n.to_value(), valid_arg_found) - .is_some() - } else { - true - } - } else { - true - }; - - if skip_current { - debug!("Parser::get_matches_with: Bumping the positional counter..."); - pos_counter + 1 - } else { - pos_counter - } - } else if trailing_values - && (self.cmd.is_allow_missing_positional_set() || contains_last) - { - // Came to -- and one positional has .last(true) set, so we go immediately - // to the last (highest index) positional - debug!("Parser::get_matches_with: .last(true) and --, setting last pos"); - positional_count - } else { - pos_counter - } - }; - // Has the user already passed '--'? Meaning only positional args follow if !trailing_values { if self.cmd.is_subcommand_precedence_over_arg_set() @@ -376,6 +305,77 @@ impl<'help, 'cmd> Parser<'help, 'cmd> { } } + // Correct pos_counter. + pos_counter = { + let is_second_to_last = pos_counter + 1 == positional_count; + + // The last positional argument, or second to last positional + // argument may be set to .multiple_values(true) or `.multiple_occurrences(true)` + let low_index_mults = is_second_to_last + && self + .cmd + .get_positionals() + .any(|a| a.is_multiple() && (positional_count != a.index.unwrap_or(0))) + && self + .cmd + .get_positionals() + .last() + .map_or(false, |p_name| !p_name.is_last_set()); + + let missing_pos = self.cmd.is_allow_missing_positional_set() + && 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 + ); + + if low_index_mults || missing_pos { + let skip_current = if let Some(n) = raw_args.peek(&args_cursor) { + if let Some(arg) = self + .cmd + .get_positionals() + .find(|a| a.index == Some(pos_counter)) + { + // If next value looks like a new_arg or it's a + // subcommand, skip positional argument under current + // pos_counter(which means current value cannot be a + // positional argument with a value next to it), assume + // current value matches the next arg. + self.is_new_arg(&n, arg) + || self + .possible_subcommand(n.to_value(), valid_arg_found) + .is_some() + } else { + true + } + } else { + true + }; + + if skip_current { + debug!("Parser::get_matches_with: Bumping the positional counter..."); + pos_counter + 1 + } else { + pos_counter + } + } else if trailing_values + && (self.cmd.is_allow_missing_positional_set() || contains_last) + { + // Came to -- and one positional has .last(true) set, so we go immediately + // to the last (highest index) positional + debug!("Parser::get_matches_with: .last(true) and --, setting last pos"); + positional_count + } else { + pos_counter + } + }; + if let Some(arg) = self.cmd.get_keymap().get(&pos_counter) { if arg.is_last_set() && !trailing_values { let _ = self.resolve_pending(matcher); @@ -738,8 +738,10 @@ impl<'help, 'cmd> Parser<'help, 'cmd> { } }; if long_arg.is_empty() { - debug_assert!(long_value.is_none(), "{:?}", long_value); - return Ok(ParseResult::NoArg); + debug_assert!( + long_value.is_some(), + "`--` should be filtered out before this point" + ); } let arg = if let Some(arg) = self.cmd.get_keymap().get(long_arg) { diff --git a/vendor/clap/src/parser/validator.rs b/vendor/clap-3.2.20/src/parser/validator.rs index ebf2b234d..ebf2b234d 100644 --- a/vendor/clap/src/parser/validator.rs +++ b/vendor/clap-3.2.20/src/parser/validator.rs diff --git a/vendor/clap/src/parser/error.rs b/vendor/clap/src/parser/error.rs deleted file mode 100644 index bdafa9ae5..000000000 --- a/vendor/clap/src/parser/error.rs +++ /dev/null @@ -1,56 +0,0 @@ -use crate::util::Id; - -/// Violation of [`ArgMatches`][crate::ArgMatches] assumptions -#[derive(Clone, Debug)] -#[allow(missing_copy_implementations)] // We might add non-Copy types in the future -#[non_exhaustive] -pub enum MatchesError { - /// Failed to downcast `AnyValue` to the specified type - #[non_exhaustive] - Downcast { - /// Type for value stored in [`ArgMatches`][crate::ArgMatches] - actual: super::AnyValueId, - /// The target type to downcast to - expected: super::AnyValueId, - }, - /// Argument not defined in [`Command`][crate::Command] - #[non_exhaustive] - UnknownArgument { - // Missing `id` but blocked on a public id type which will hopefully come with `unstable-v4` - }, -} - -impl MatchesError { - #[track_caller] - pub(crate) fn unwrap<T>(id: &Id, r: Result<T, MatchesError>) -> T { - let err = match r { - Ok(t) => { - return t; - } - Err(err) => err, - }; - panic!( - "Mismatch between definition and access of `{:?}`. {}", - id, err - ) - } -} - -impl std::error::Error for MatchesError {} - -impl std::fmt::Display for MatchesError { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - match self { - Self::Downcast { actual, expected } => { - writeln!( - f, - "Could not downcast to {:?}, need to downcast to {:?}", - expected, actual - ) - } - Self::UnknownArgument {} => { - writeln!(f, "Unknown argument or group id. Make sure you are using the argument id and not the short or long flags") - } - } - } -} |