Skip to content

Commit

Permalink
fix: Ease transition for now-default settings
Browse files Browse the repository at this point in the history
We prefer Settings to always be off by default, so when we change a
default, we have to rename.

This adds back in the now-default settings with deprecation messages to
help the user know how things now work.

Unfortunately, there is no way to notify the user that the default they
relied on has changed.  This also doesn't help us when the change in
behavior is more than just an inverting, like `InvalidUtf8` or when a
setting mapped to multiple bits.
  • Loading branch information
epage committed Oct 27, 2021
1 parent 9905801 commit 4835c00
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/build/app/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ bitflags! {
const IGNORE_ERRORS = 1 << 44;
#[cfg(feature = "unstable-multicall")]
const MULTICALL = 1 << 45;
const NO_OP = 0;
}
}

Expand All @@ -72,6 +73,8 @@ impl_settings! { AppSettings, AppFlags,
=> Flags::ARGS_NEGATE_SCS,
AllowExternalSubcommands("allowexternalsubcommands")
=> Flags::ALLOW_UNK_SC,
StrictUtf8("strictutf8")
=> Flags::NO_OP,
AllowInvalidUtf8ForExternalSubcommands("allowinvalidutf8forexternalsubcommands")
=> Flags::SC_UTF8_NONE,
AllowLeadingHyphen("allowleadinghyphen")
Expand All @@ -80,6 +83,8 @@ impl_settings! { AppSettings, AppFlags,
=> Flags::ALLOW_NEG_NUMS,
AllowMissingPositional("allowmissingpositional")
=> Flags::ALLOW_MISSING_POS,
ColoredHelp("coloredhelp")
=> Flags::NO_OP,
ColorAlways("coloralways")
=> Flags::COLOR_ALWAYS,
ColorAuto("colorauto")
Expand Down Expand Up @@ -131,6 +136,7 @@ impl_settings! { AppSettings, AppFlags,
=> Flags::USE_LONG_FORMAT_FOR_HELP_SC,
TrailingVarArg("trailingvararg")
=> Flags::TRAILING_VARARG,
UnifiedHelp("unifiedhelp") => Flags::NO_OP,
NextLineHelp("nextlinehelp")
=> Flags::NEXT_LINE_HELP,
IgnoreErrors("ignoreerrors")
Expand All @@ -157,6 +163,13 @@ impl_settings! { AppSettings, AppFlags,
/// [`App`]: crate::App
#[derive(Debug, PartialEq, Copy, Clone)]
pub enum AppSettings {
/// Deprecated, this is now the default, see [`AppSettings::AllowInvalidUtf8ForExternalSubcommands`] and [`ArgSettings::AllowInvalidUtf8ForExternalSubcommands`] for the opposite.
#[deprecated(
since = "3.0.0",
note = "This is now the default see [`AppSettings::AllowInvalidUtf8ForExternalSubcommands`] and [`ArgSettings::AllowInvalidUtf8ForExternalSubcommands`] for the opposite."
)]
StrictUtf8,

/// Specifies that external subcommands that are invalid UTF-8 should *not* be treated as an error.
///
/// **NOTE:** Using external subcommand argument values with invalid UTF-8 requires using
Expand Down Expand Up @@ -498,6 +511,10 @@ pub enum AppSettings {
/// ```
SubcommandPrecedenceOverArg,

/// Deprecated, this is now the default
#[deprecated(since = "3.0.0", note = "This is now the default")]
ColoredHelp,

/// Deprecated, see [`App::color`]
#[deprecated(since = "3.0.0", note = "Replaced with `App::color`")]
ColorAuto,
Expand Down Expand Up @@ -1023,6 +1040,10 @@ pub enum AppSettings {
/// [`Arg::multiple_values(true)`]: crate::Arg::multiple_values()
TrailingVarArg,

/// Deprecated, this is now the default
#[deprecated(since = "3.0.0", note = "This is now the default")]
UnifiedHelp,

/// Will display a message "Press \[ENTER\]/\[RETURN\] to continue..." and wait for user before
/// exiting
///
Expand Down
9 changes: 9 additions & 0 deletions src/build/arg/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ bitflags! {
#[cfg(feature = "env")]
const HIDE_ENV = 1 << 21;
const UTF8_NONE = 1 << 22;
const NO_OP = 0;
}
}

Expand All @@ -51,6 +52,7 @@ impl_settings! { ArgSettings, ArgFlags,
MultipleValues("multiplevalues") => Flags::MULTIPLE_VALS,
Multiple("multiple") => Flags::MULTIPLE,
ForbidEmptyValues("forbidemptyvalues") => Flags::NO_EMPTY_VALS,
EmptyValues("emptyvalues") => Flags::NO_OP,
Hidden("hidden") => Flags::HIDDEN,
TakesValue("takesvalue") => Flags::TAKES_VAL,
UseValueDelimiter("usevaluedelimiter") => Flags::USE_DELIM,
Expand Down Expand Up @@ -97,6 +99,13 @@ pub enum ArgSettings {
Multiple,
/// Forbids an arg from accepting empty values such as `""`
ForbidEmptyValues,
/// Deprecated, this is now the default, see [`ArgSettings::ForbidEmptyValues`] for the
/// opposite.
#[deprecated(
since = "3.0.0",
note = "This is now the default see [`ArgSettings::ForbidEmptyValues`] for the opposite."
)]
EmptyValues,
/// Hides an arg from the help message
Hidden,
/// Allows an argument to take a value (such as `--option value`)
Expand Down

0 comments on commit 4835c00

Please sign in to comment.