Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Avoid direct member access #3380

Merged
merged 6 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/build/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2659,7 +2659,7 @@ impl<'help> App<'help> {
.filter(|a| a.get_global())
.map(|ga| ga.id.clone())
.collect();
if let Some(used_subcommand) = matcher.0.subcommand.as_ref() {
if let Some(used_subcommand) = matcher.subcommand.as_ref() {
if let Some(used_subcommand) = self
.subcommands
.iter()
Expand Down
12 changes: 6 additions & 6 deletions src/build/app/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ pub enum AppSettings {
/// "myprog",
/// ]);
/// assert!(err.is_err());
/// assert_eq!(err.unwrap_err().kind, ErrorKind::MissingSubcommand);
/// assert_eq!(err.unwrap_err().kind(), ErrorKind::MissingSubcommand);
/// # ;
/// ```
///
Expand Down Expand Up @@ -434,7 +434,7 @@ pub enum AppSettings {
/// .subcommand(App::new("dnsdomainname"));
/// let m = app.try_get_matches_from_mut(&["/usr/bin/hostname", "dnsdomainname"]);
/// assert!(m.is_err());
/// assert_eq!(m.unwrap_err().kind, ErrorKind::UnknownArgument);
/// assert_eq!(m.unwrap_err().kind(), ErrorKind::UnknownArgument);
/// let m = app.get_matches_from(&["/usr/bin/dnsdomainname"]);
/// assert_eq!(m.subcommand_name(), Some("dnsdomainname"));
/// ```
Expand Down Expand Up @@ -574,7 +574,7 @@ pub enum AppSettings {
/// "myprog"
/// ]);
/// assert!(err.is_err());
/// assert_eq!(err.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
/// assert_eq!(err.unwrap_err().kind(), ErrorKind::MissingRequiredArgument);
/// # ;
/// ```
///
Expand Down Expand Up @@ -766,7 +766,7 @@ pub enum AppSettings {
/// "myprog", "-h"
/// ]);
/// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::UnknownArgument);
/// assert_eq!(res.unwrap_err().kind(), ErrorKind::UnknownArgument);
/// ```
DisableHelpFlag,

Expand All @@ -785,7 +785,7 @@ pub enum AppSettings {
/// "myprog", "help"
/// ]);
/// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::UnknownArgument);
/// assert_eq!(res.unwrap_err().kind(), ErrorKind::UnknownArgument);
/// ```
///
/// [`subcommand`]: crate::App::subcommand()
Expand All @@ -803,7 +803,7 @@ pub enum AppSettings {
/// "myprog", "-V"
/// ]);
/// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::UnknownArgument);
/// assert_eq!(res.unwrap_err().kind(), ErrorKind::UnknownArgument);
/// ```
DisableVersionFlag,

Expand Down
58 changes: 29 additions & 29 deletions src/build/arg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ impl<'help> Arg<'help> {
/// ]);
///
/// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::UnknownArgument);
/// assert_eq!(res.unwrap_err().kind(), ErrorKind::UnknownArgument);
/// ```
/// [index]: Arg::index()
/// [`UnknownArgument`]: crate::ErrorKind::UnknownArgument
Expand Down Expand Up @@ -607,7 +607,7 @@ impl<'help> Arg<'help> {
/// ]);
///
/// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
/// assert_eq!(res.unwrap_err().kind(), ErrorKind::MissingRequiredArgument);
/// ```
#[inline]
#[must_use]
Expand Down Expand Up @@ -672,7 +672,7 @@ impl<'help> Arg<'help> {
/// ]);
///
/// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
/// assert_eq!(res.unwrap_err().kind(), ErrorKind::MissingRequiredArgument);
/// ```
/// [`Arg::requires(name)`]: Arg::requires()
/// [Conflicting]: Arg::conflicts_with()
Expand Down Expand Up @@ -713,7 +713,7 @@ impl<'help> Arg<'help> {
/// ]);
///
/// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::ArgumentConflict);
/// assert_eq!(res.unwrap_err().kind(), ErrorKind::ArgumentConflict);
/// ```
#[inline]
#[must_use]
Expand Down Expand Up @@ -869,7 +869,7 @@ impl<'help> Arg<'help> {
/// ]);
///
/// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::TooManyOccurrences);
/// assert_eq!(res.unwrap_err().kind(), ErrorKind::TooManyOccurrences);
/// ```
/// [`Arg::multiple_occurrences(true)`]: Arg::multiple_occurrences()
#[inline]
Expand Down Expand Up @@ -1083,7 +1083,7 @@ impl<'help> Arg<'help> {
/// ]);
///
/// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::UnexpectedMultipleUsage)
/// assert_eq!(res.unwrap_err().kind(), ErrorKind::UnexpectedMultipleUsage)
/// ```
///
/// A common mistake is to define an option which allows multiple values, and a positional
Expand Down Expand Up @@ -1151,7 +1151,7 @@ impl<'help> Arg<'help> {
/// ]);
///
/// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::UnknownArgument);
/// assert_eq!(res.unwrap_err().kind(), ErrorKind::UnknownArgument);
/// ```
///
/// [`subcommands`]: crate::App::subcommand()
Expand Down Expand Up @@ -1206,7 +1206,7 @@ impl<'help> Arg<'help> {
/// ]);
///
/// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::WrongNumberOfValues);
/// assert_eq!(res.unwrap_err().kind(), ErrorKind::WrongNumberOfValues);
/// ```
/// [`Arg::multiple_occurrences(true)`]: Arg::multiple_occurrences()
#[inline]
Expand Down Expand Up @@ -1270,7 +1270,7 @@ impl<'help> Arg<'help> {
/// ]);
///
/// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::UnknownArgument);
/// assert_eq!(res.unwrap_err().kind(), ErrorKind::UnknownArgument);
/// ```
/// [`Arg::multiple_occurrences(true)`]: Arg::multiple_occurrences()
#[inline]
Expand Down Expand Up @@ -1335,7 +1335,7 @@ impl<'help> Arg<'help> {
/// ]);
///
/// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::TooFewValues);
/// assert_eq!(res.unwrap_err().kind(), ErrorKind::TooFewValues);
/// ```
/// [`Arg::multiple_occurrences(true)`]: Arg::multiple_occurrences()
#[inline]
Expand Down Expand Up @@ -1635,7 +1635,7 @@ impl<'help> Arg<'help> {
/// "prog", "12345"
/// ]);
/// assert!(res.is_err());
/// assert_eq!(res.err().unwrap().kind, ErrorKind::ValueValidation)
/// assert_eq!(res.err().unwrap().kind(), ErrorKind::ValueValidation)
/// ```
#[cfg(feature = "regex")]
#[must_use]
Expand Down Expand Up @@ -1720,7 +1720,7 @@ impl<'help> Arg<'help> {
/// "prog", "--mode", "wrong"
/// ]);
/// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::InvalidValue);
/// assert_eq!(res.unwrap_err().kind(), ErrorKind::InvalidValue);
/// ```
/// [options]: Arg::takes_value()
/// [positional arguments]: Arg::index()
Expand Down Expand Up @@ -1796,7 +1796,7 @@ impl<'help> Arg<'help> {
/// "prog", "--mode", "wrong"
/// ]);
/// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::InvalidValue);
/// assert_eq!(res.unwrap_err().kind(), ErrorKind::InvalidValue);
/// ```
/// [options]: Arg::takes_value()
/// [positional arguments]: Arg::index()
Expand Down Expand Up @@ -1916,7 +1916,7 @@ impl<'help> Arg<'help> {
/// ]);
///
/// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::UnknownArgument);
/// assert_eq!(res.unwrap_err().kind(), ErrorKind::UnknownArgument);
/// ```
/// [`Arg::number_of_values(1)`]: Arg::number_of_values()
#[inline]
Expand Down Expand Up @@ -2013,7 +2013,7 @@ impl<'help> Arg<'help> {
/// ]);
///
/// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::EmptyValue);
/// assert_eq!(res.unwrap_err().kind(), ErrorKind::EmptyValue);
/// ```
#[inline]
#[must_use]
Expand Down Expand Up @@ -2065,7 +2065,7 @@ impl<'help> Arg<'help> {
/// ]);
///
/// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::NoEquals);
/// assert_eq!(res.unwrap_err().kind(), ErrorKind::NoEquals);
/// ```
#[inline]
#[must_use]
Expand Down Expand Up @@ -2223,7 +2223,7 @@ impl<'help> Arg<'help> {
///
/// assert!(res.is_err());
/// let err = res.unwrap_err();
/// assert_eq!(err.kind, ErrorKind::UnknownArgument);
/// assert_eq!(err.kind(), ErrorKind::UnknownArgument);
/// ```
///
/// What's happening is `-o` is getting `val1`, and because delimiters are required yet none
Expand Down Expand Up @@ -3643,7 +3643,7 @@ impl<'help> Arg<'help> {
/// ]);
///
/// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
/// assert_eq!(res.unwrap_err().kind(), ErrorKind::MissingRequiredArgument);
/// ```
/// [required]: Arg::required()
#[must_use]
Expand Down Expand Up @@ -3712,7 +3712,7 @@ impl<'help> Arg<'help> {
/// ]);
///
/// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
/// assert_eq!(res.unwrap_err().kind(), ErrorKind::MissingRequiredArgument);
/// ```
/// [required]: Arg::required()
/// [`Arg::required_unless_present_any`]: Arg::required_unless_present_any()
Expand Down Expand Up @@ -3789,7 +3789,7 @@ impl<'help> Arg<'help> {
/// ]);
///
/// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
/// assert_eq!(res.unwrap_err().kind(), ErrorKind::MissingRequiredArgument);
/// ```
/// [required]: Arg::required()
/// [`Arg::required_unless_present_any(names)`]: Arg::required_unless_present_any()
Expand Down Expand Up @@ -3848,7 +3848,7 @@ impl<'help> Arg<'help> {
///
/// // We did use --other=special so "cfg" had become required but was missing.
/// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
/// assert_eq!(res.unwrap_err().kind(), ErrorKind::MissingRequiredArgument);
///
/// let res = App::new("prog")
/// .arg(Arg::new("cfg")
Expand Down Expand Up @@ -3880,7 +3880,7 @@ impl<'help> Arg<'help> {
///
/// // However, case-insensitive comparisons can be enabled. This typically occurs when using Arg::possible_values().
/// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
/// assert_eq!(res.unwrap_err().kind(), ErrorKind::MissingRequiredArgument);
/// ```
/// [`Arg::requires(name)`]: Arg::requires()
/// [Conflicting]: Arg::conflicts_with()
Expand Down Expand Up @@ -3959,7 +3959,7 @@ impl<'help> Arg<'help> {
/// ]);
///
/// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
/// assert_eq!(res.unwrap_err().kind(), ErrorKind::MissingRequiredArgument);
/// ```
/// [`Arg::requires(name)`]: Arg::requires()
/// [Conflicting]: Arg::conflicts_with()
Expand Down Expand Up @@ -4039,7 +4039,7 @@ impl<'help> Arg<'help> {
/// ]);
///
/// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
/// assert_eq!(res.unwrap_err().kind(), ErrorKind::MissingRequiredArgument);
/// ```
/// [required]: Arg::required()
#[must_use]
Expand Down Expand Up @@ -4101,7 +4101,7 @@ impl<'help> Arg<'help> {
/// ]);
///
/// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
/// assert_eq!(res.unwrap_err().kind(), ErrorKind::MissingRequiredArgument);
/// ```
/// [`Arg::requires(name)`]: Arg::requires()
/// [Conflicting]: Arg::conflicts_with()
Expand Down Expand Up @@ -4153,7 +4153,7 @@ impl<'help> Arg<'help> {
/// ]);
///
/// assert!(res.is_err()); // We used --config=special.conf so --option <val> is required
/// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
/// assert_eq!(res.unwrap_err().kind(), ErrorKind::MissingRequiredArgument);
/// ```
/// [`Arg::requires(name)`]: Arg::requires()
/// [Conflicting]: Arg::conflicts_with()
Expand Down Expand Up @@ -4225,7 +4225,7 @@ impl<'help> Arg<'help> {
///
/// assert!(res.is_err());
/// // We didn't use output
/// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
/// assert_eq!(res.unwrap_err().kind(), ErrorKind::MissingRequiredArgument);
/// ```
/// [Conflicting]: Arg::conflicts_with()
/// [override]: Arg::overrides_with()
Expand Down Expand Up @@ -4275,7 +4275,7 @@ impl<'help> Arg<'help> {
/// ]);
///
/// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::ArgumentConflict);
/// assert_eq!(res.unwrap_err().kind(), ErrorKind::ArgumentConflict);
/// ```
///
/// [`Arg::conflicts_with_all(names)`]: Arg::conflicts_with_all()
Expand Down Expand Up @@ -4329,7 +4329,7 @@ impl<'help> Arg<'help> {
/// ]);
///
/// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::ArgumentConflict);
/// assert_eq!(res.unwrap_err().kind(), ErrorKind::ArgumentConflict);
/// ```
/// [`Arg::conflicts_with`]: Arg::conflicts_with()
/// [`Arg::exclusive(true)`]: Arg::exclusive()
Expand Down
8 changes: 4 additions & 4 deletions src/build/arg/possible_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ use crate::util::eq_ignore_case;
/// [help]: PossibleValue::help()
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct PossibleValue<'help> {
pub(crate) name: &'help str,
pub(crate) help: Option<&'help str>,
pub(crate) aliases: Vec<&'help str>, // (name, visible)
pub(crate) hide: bool,
name: &'help str,
help: Option<&'help str>,
aliases: Vec<&'help str>, // (name, visible)
hide: bool,
}

impl<'help> PossibleValue<'help> {
Expand Down
Loading