From cacc23473c64ec8a57471285b3978face05b4d86 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Wed, 19 Jun 2019 16:58:18 -0700 Subject: [PATCH] Remove v2 depecated features. This patch: * Removes the `ArgSettings::Global` variant, and replaces all users of it to `Arg::global(...)`. The variant itself is lifted up into a field on Arg. This was deprecated in clap 2.32.0. * Removes AppFlags::PropagateGlobalValuesDown. This was deprecated in clap 2.27.0. * Removes `Arg::empty_values`. This was deprecated in clap 2.30.0. * Removes `ArgMatches::usage`. This was deprecated in clap 2.32.0. --- benches/03_complex.rs | 5 ++-- src/build/app/mod.rs | 6 ++--- src/build/app/settings.rs | 41 -------------------------------- src/build/arg/mod.rs | 30 ++++++----------------- src/build/arg/settings.rs | 10 -------- src/parse/matches/arg_matches.rs | 8 ------- tests/propagate_globals.rs | 6 ++--- 7 files changed, 16 insertions(+), 90 deletions(-) diff --git a/benches/03_complex.rs b/benches/03_complex.rs index d4adb669..f4025dcc 100644 --- a/benches/03_complex.rs +++ b/benches/03_complex.rs @@ -19,7 +19,7 @@ macro_rules! create_app { .author("Kevin K. ") .arg("-o --option=[opt]... 'tests options'") .arg("[positional] 'tests positionals'") - .arg(Arg::from("-f --flag... 'tests flags'").setting(ArgSettings::Global)) + .arg(Arg::from("-f --flag... 'tests flags'").global(true)) .args(&[ Arg::from("[flag2] -F 'tests flags with exclusions'") .conflicts_with("flag") @@ -76,7 +76,8 @@ fn create_app_builder(b: &mut Bencher) { .short('f') .help("tests flags") .long("flag") - .settings(&[ArgSettings::MultipleOccurrences, ArgSettings::Global]), + .global(true) + .settings(&[ArgSettings::MultipleOccurrences]), ) .arg( Arg::with_name("flag2") diff --git a/src/build/app/mod.rs b/src/build/app/mod.rs index fa312690..b2537fc5 100644 --- a/src/build/app/mod.rs +++ b/src/build/app/mod.rs @@ -1398,7 +1398,7 @@ impl<'b> App<'b> { .args .args .iter() - .filter(|a| a.is_set(ArgSettings::Global)) + .filter(|a| a.global) .map(|ga| ga.id) .collect(); @@ -1515,7 +1515,7 @@ impl<'b> App<'b> { .args .args .iter() - .filter(|a| a.is_set(ArgSettings::Global)) + .filter(|a| a.global) { $sc.args.push(a.clone()); } @@ -1666,7 +1666,7 @@ impl<'b> App<'b> { ); } assert!( - !(a.is_set(ArgSettings::Required) && a.is_set(ArgSettings::Global)), + !(a.is_set(ArgSettings::Required) && a.global), "Global arguments cannot be required.\n\n\t'{}' is marked as \ global and required", a.name diff --git a/src/build/app/settings.rs b/src/build/app/settings.rs index 5407144d..cec618c1 100644 --- a/src/build/app/settings.rs +++ b/src/build/app/settings.rs @@ -61,7 +61,6 @@ impl Default for AppFlags { fn default() -> Self { AppFlags(Flags::UTF8_NONE | Flags::COLOR_AUTO) } } -#[allow(deprecated)] impl AppFlags { pub fn new() -> Self { AppFlags::default() } pub fn zeroed() -> Self { AppFlags(Flags::empty()) } @@ -90,7 +89,6 @@ impl AppFlags { NoAutoHelp => Flags::NO_AUTO_HELP, NoAutoVersion => Flags::NO_AUTO_VERSION, NoBinaryName => Flags::NO_BIN_NAME, - PropagateGlobalValuesDown=> Flags::PROPAGATE_VALS_DOWN, StrictUtf8 => Flags::UTF8_STRICT, SubcommandsNegateReqs => Flags::SC_NEGATE_REQS, SubcommandRequired => Flags::SC_REQUIRED, @@ -669,45 +667,6 @@ pub enum AppSettings { /// ``` NextLineHelp, - /// **DEPRECATED**: This setting is no longer required in order to propagate values up or down - /// - /// Specifies that the parser should propagate global arg's values down or up through any *used* - /// child subcommands. Meaning, if a subcommand wasn't used, the values won't be propagated to - /// said subcommand. - /// - /// # Examples - /// - /// ```rust - /// # use clap::{App, Arg, AppSettings, }; - /// let m = App::new("myprog") - /// .arg(Arg::from("[cmd] 'command to run'") - /// .global(true)) - /// .subcommand(App::new("foo")) - /// .get_matches_from(vec!["myprog", "set", "foo"]); - /// - /// assert_eq!(m.value_of("cmd"), Some("set")); - /// - /// let sub_m = m.subcommand_matches("foo").unwrap(); - /// assert_eq!(sub_m.value_of("cmd"), Some("set")); - /// ``` - /// Now doing the same thing, but *not* using any subcommands will result in the value not being - /// propagated down. - /// - /// ```rust - /// # use clap::{App, Arg, AppSettings, }; - /// let m = App::new("myprog") - /// .arg(Arg::from("[cmd] 'command to run'") - /// .global(true)) - /// .subcommand(App::new("foo")) - /// .get_matches_from(vec!["myprog", "set"]); - /// - /// assert_eq!(m.value_of("cmd"), Some("set")); - /// - /// assert!(m.subcommand_matches("foo").is_none()); - /// ``` - #[deprecated(since = "2.27.0", note = "No longer required to propagate values")] - PropagateGlobalValuesDown, - /// Allows [``]s to override all requirements of the parent command. /// For example if you had a subcommand or top level application with a required argument /// that is only required as long as there is no subcommand present, diff --git a/src/build/arg/mod.rs b/src/build/arg/mod.rs index b1655252..b6fc4cfe 100644 --- a/src/build/arg/mod.rs +++ b/src/build/arg/mod.rs @@ -114,6 +114,8 @@ pub struct Arg<'help> { pub r_ifs: Option>, #[doc(hidden)] pub help_heading: Option<&'help str>, + #[doc(hidden)] + pub global: bool, } impl<'help> Arg<'help> { @@ -191,7 +193,6 @@ impl<'help> Arg<'help> { "multiple" => yaml_to_bool!(a, v, multiple), "hidden" => yaml_to_bool!(a, v, hidden), "next_line_help" => yaml_to_bool!(a, v, next_line_help), - "empty_values" => yaml_to_bool!(a, v, empty_values), "group" => yaml_to_str!(a, v, group), "number_of_values" => yaml_to_u64!(a, v, number_of_values), "max_values" => yaml_to_u64!(a, v, max_values), @@ -3020,7 +3021,7 @@ impl<'help> Arg<'help> { /// # use clap::{App, Arg, ArgSettings}; /// Arg::with_name("debug") /// .short('d') - /// .setting(ArgSettings::Global) + /// .global(true) /// # ; /// ``` /// @@ -3034,7 +3035,7 @@ impl<'help> Arg<'help> { /// .arg(Arg::with_name("verb") /// .long("verbose") /// .short('v') - /// .setting(ArgSettings::Global)) + /// .global(true)) /// .subcommand(App::new("test")) /// .subcommand(App::new("do-stuff")) /// .get_matches_from(vec![ @@ -3050,12 +3051,9 @@ impl<'help> Arg<'help> { /// [`ArgMatches`]: ./struct.ArgMatches.html /// [`ArgMatches::is_present("flag")`]: ./struct.ArgMatches.html#method.is_present /// [`Arg`]: ./struct.Arg.html - pub fn global(self, g: bool) -> Self { - if g { - self.setting(ArgSettings::Global) - } else { - self.unset_setting(ArgSettings::Global) - } + pub fn global(mut self, g: bool) -> Self { + self.global = g; + self } /// Specifies that *multiple values* may only be set using the delimiter. This means if an @@ -3210,20 +3208,6 @@ impl<'help> Arg<'help> { } } - /// **Deprecated** - #[deprecated( - since = "2.30.0", - note = "Use `Arg::setting(ArgSettings::AllowEmptyValues)` instead. Will be removed in v3.0-beta" - )] - pub fn empty_values(mut self, ev: bool) -> Self { - if ev { - self.setting(ArgSettings::AllowEmptyValues) - } else { - self = self.setting(ArgSettings::TakesValue); - self.unset_setting(ArgSettings::AllowEmptyValues) - } - } - /// Hides an argument from help message output. /// /// **NOTE:** This does **not** hide the argument from usage strings on error diff --git a/src/build/arg/settings.rs b/src/build/arg/settings.rs index 89aa9f42..0d431fd8 100644 --- a/src/build/arg/settings.rs +++ b/src/build/arg/settings.rs @@ -40,7 +40,6 @@ impl ArgFlags { MultipleOccurrences => Flags::MULTIPLE_OCC, MultipleValues => Flags::MULTIPLE_VALS, AllowEmptyValues => Flags::EMPTY_VALS, - Global => Flags::GLOBAL, Hidden => Flags::HIDDEN, TakesValue => Flags::TAKES_VAL, UseValueDelimiter => Flags::USE_DELIM, @@ -82,10 +81,6 @@ pub enum ArgSettings { MultipleOccurrences, /// Allows an arg accept empty values such as `""` AllowEmptyValues, - /// Sets an arg to be global (i.e. exist in all subcommands) - /// **DEPRECATED** - #[deprecated(since = "2.32.0", note = "Use `App::global_arg` instead")] - Global, /// Hides an arg from the help message Hidden, /// Allows an argument to take a value (such as `--option value`) @@ -128,7 +123,6 @@ impl FromStr for ArgSettings { fn from_str(s: &str) -> Result::Err> { match &*s.to_ascii_lowercase() { "required" => Ok(ArgSettings::Required), - "global" => Ok(ArgSettings::Global), "allowemptyvalues" => Ok(ArgSettings::AllowEmptyValues), "hidden" => Ok(ArgSettings::Hidden), "takesvalue" => Ok(ArgSettings::TakesValue), @@ -165,10 +159,6 @@ mod test { "allowemptyvalues".parse::().unwrap(), ArgSettings::AllowEmptyValues ); - assert_eq!( - "global".parse::().unwrap(), - ArgSettings::Global - ); assert_eq!( "hidepossiblevalues".parse::().unwrap(), ArgSettings::HidePossibleValues diff --git a/src/parse/matches/arg_matches.rs b/src/parse/matches/arg_matches.rs index 57e75594..7821bb60 100644 --- a/src/parse/matches/arg_matches.rs +++ b/src/parse/matches/arg_matches.rs @@ -744,14 +744,6 @@ impl ArgMatches { .as_ref() .map_or(("", None), |sc| (&sc.name[..], Some(&sc.matches))) } - - // @TODO @v3-beta: remove - /// **Deprecated** - #[deprecated( - since = "2.32.0", - note = "Use App::usage instead. Will be removed in v3-beta" - )] - pub fn usage(&self) -> &str { panic!("Use App::usage instead. Will be removed in v3-beta") } } // The following were taken and adapated from vec_map source diff --git a/tests/propagate_globals.rs b/tests/propagate_globals.rs index cfc28a0a..961f1f5d 100644 --- a/tests/propagate_globals.rs +++ b/tests/propagate_globals.rs @@ -12,7 +12,7 @@ mod tests { Arg::with_name("GLOBAL_ARG") .long("global-arg") .help("Specifies something needed by the subcommands") - .setting(ArgSettings::Global) + .global(true) .setting(ArgSettings::TakesValue) .default_value("default_value"), ) @@ -20,8 +20,8 @@ mod tests { Arg::with_name("GLOBAL_FLAG") .long("global-flag") .help("Specifies something needed by the subcommands") - .setting(ArgSettings::MultipleOccurrences) - .setting(ArgSettings::Global), + .global(true) + .setting(ArgSettings::MultipleOccurrences), ) .subcommand(App::new("outer").subcommand(App::new("inner"))) }