Skip to content

Commit

Permalink
fix: Ease clap2->3 transition with renamed Settings
Browse files Browse the repository at this point in the history
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 clap-rs#2617
  • Loading branch information
epage committed Oct 26, 2021
1 parent c0ac536 commit e602e24
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/build/app/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
///
Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions src/build/arg/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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")]
Expand All @@ -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
Expand All @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)*])*
Expand All @@ -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)*])*
Expand All @@ -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)*])*
Expand Down Expand Up @@ -616,6 +619,8 @@ macro_rules! impl_settings {
impl FromStr for $settings {
type Err = String;
fn from_str(s: &str) -> Result<Self, <Self as FromStr>::Err> {
#[allow(deprecated)] // some Settings might be deprecated
#[allow(unreachable_patterns)] // some Settings might be deprecated
match &*s.to_ascii_lowercase() {
$(
$(#[$inner $($args)*])*
Expand Down

0 comments on commit e602e24

Please sign in to comment.