From 475c88ba66fc597809c38065db2b19fba7eabfdd Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 4 Oct 2021 10:53:53 -0500 Subject: [PATCH] fix: Ease clap2->3 transition with renamed Settings This brings back the old name of settings, just deprecated. Since they all map to the same bits in the bit field, this should work for `setting` and `is_set`. The only thing this lacks is being able to do equality across variants, whcih seems like a minority case. Removed settings have some extra care abouts that we'll need to look into separately. This is a part of #2617 --- src/build/app/settings.rs | 24 ++++++++++++++++++++++++ src/build/arg/settings.rs | 13 +++++++++++++ src/macros.rs | 5 +++++ 3 files changed, 42 insertions(+) diff --git a/src/build/app/settings.rs b/src/build/app/settings.rs index 383605a138ce..e0b6f7c96ad9 100644 --- a/src/build/app/settings.rs +++ b/src/build/app/settings.rs @@ -87,10 +87,16 @@ impl_settings! { AppSettings, AppFlags, => Flags::DISABLE_HELP_SC, DisableHelpFlag("disablehelpflag") => Flags::DISABLE_HELP_FLAG, + DisableHelpFlags("disablehelpflag") + => Flags::DISABLE_HELP_FLAG, DisableVersionFlag("disableversionflag") => Flags::DISABLE_VERSION_FLAG, + DisableVersion("disableversionflag") + => Flags::DISABLE_VERSION_FLAG, PropagateVersion("propagateversion") => Flags::PROPAGATE_VERSION, + GlobalVersion("propagateversion") + => Flags::PROPAGATE_VERSION, HidePossibleValuesInHelp("hidepossiblevaluesinhelp") => Flags::NO_POS_VALUES, HelpRequired("helprequired") @@ -530,6 +536,10 @@ pub enum AppSettings { /// ``` DisableHelpFlag, + /// Deprecated, see [`AppSettings::DisableHelpFlag`] + #[deprecated(since = "3.0.0", note = "Replaced with `AppSettings::DisableHelpFlag`")] + DisableHelpFlags, + /// Disables the `help` [`subcommand`]. /// /// # Examples @@ -567,6 +577,13 @@ pub enum AppSettings { /// ``` DisableVersionFlag, + /// Deprecated, see [`AppSettings::DisableVersionFlag`] + #[deprecated( + since = "3.0.0", + note = "Replaced with `AppSettings::DisableVersionFlag`" + )] + DisableVersion, + /// Displays the arguments and [`subcommands`] in the help message in the order that they were /// declared in, and not alphabetically which is the default. /// @@ -688,6 +705,13 @@ pub enum AppSettings { /// [`subcommands`]: crate::App::subcommand() PropagateVersion, + /// Deprecated, see [`AppSettings::PropagateVersion`] + #[deprecated( + since = "3.0.0", + note = "Replaced with `AppSettings::PropagateVersion`" + )] + GlobalVersion, + /// Specifies that this [`subcommand`] should be hidden from help messages /// /// # Examples diff --git a/src/build/arg/settings.rs b/src/build/arg/settings.rs index 152ad4568886..ccb3738a4b6f 100644 --- a/src/build/arg/settings.rs +++ b/src/build/arg/settings.rs @@ -28,6 +28,7 @@ bitflags! { const HIDDEN_SHORT_H = 1 << 18; const HIDDEN_LONG_H = 1 << 19; const MULTIPLE_VALS = 1 << 20; + const MULTIPLE = Self::MULTIPLE_OCC.bits | Self::MULTIPLE_VALS.bits; #[cfg(feature = "env")] const HIDE_ENV = 1 << 21; const UTF8_NONE = 1 << 22; @@ -49,6 +50,7 @@ impl_settings! { ArgSettings, ArgFlags, Required("required") => Flags::REQUIRED, MultipleOccurrences("multipleoccurrences") => Flags::MULTIPLE_OCC, MultipleValues("multiplevalues") => Flags::MULTIPLE_VALS, + Multiple("multiple") => Flags::MULTIPLE, ForbidEmptyValues("forbidemptyvalues") => Flags::NO_EMPTY_VALS, Hidden("hidden") => Flags::HIDDEN, TakesValue("takesvalue") => Flags::TAKES_VAL, @@ -61,6 +63,7 @@ impl_settings! { ArgSettings, ArgFlags, RequireEquals("requireequals") => Flags::REQUIRE_EQUALS, Last("last") => Flags::LAST, IgnoreCase("ignorecase") => Flags::CASE_INSENSITIVE, + CaseInsensitive("ignorecase") => Flags::CASE_INSENSITIVE, #[cfg(feature = "env")] HideEnv("hideenv") => Flags::HIDE_ENV, #[cfg(feature = "env")] @@ -87,6 +90,13 @@ pub enum ArgSettings { MultipleValues, /// Allows an arg to appear multiple times MultipleOccurrences, + /// Deprecated, see [`ArgSettings::MultipleOccurrences`] (most likely what you want) and + /// [`ArgSettings::MultipleValues`] + #[deprecated( + since = "3.0.0", + note = "Split into `ArgSettings::MultipleOccurrences` (most likely what you want) and `ArgSettings::MultipleValues`" + )] + Multiple, /// Forbids an arg from accepting empty values such as `""` ForbidEmptyValues, /// Hides an arg from the help message @@ -113,6 +123,9 @@ pub enum ArgSettings { HideDefaultValue, /// Possible values become case insensitive IgnoreCase, + /// Deprecated, see [`ArgSettings::IgnoreCase`] + #[deprecated(since = "3.0.0", note = "Replaced with `ArgSettings::IgnoreCase`")] + CaseInsensitive, /// Hides environment variable arguments from the help message #[cfg(feature = "env")] HideEnv, diff --git a/src/macros.rs b/src/macros.rs index be9575804fe2..02ea91c834dc 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -549,6 +549,7 @@ macro_rules! impl_settings { } pub(crate) fn set(&mut self, s: $settings) { + #[allow(deprecated)] // some Settings might be deprecated match s { $( $(#[$inner $($args)*])* @@ -558,6 +559,7 @@ macro_rules! impl_settings { } pub(crate) fn unset(&mut self, s: $settings) { + #[allow(deprecated)] // some Settings might be deprecated match s { $( $(#[$inner $($args)*])* @@ -567,6 +569,7 @@ macro_rules! impl_settings { } pub(crate) fn is_set(&self, s: $settings) -> bool { + #[allow(deprecated)] // some Settings might be deprecated match s { $( $(#[$inner $($args)*])* @@ -616,6 +619,8 @@ macro_rules! impl_settings { impl FromStr for $settings { type Err = String; fn from_str(s: &str) -> Result::Err> { + #[allow(deprecated)] // some Settings might be deprecated + #[allow(unreachable_patterns)] // some Settings might be deprecated match &*s.to_ascii_lowercase() { $( $(#[$inner $($args)*])*