Skip to content

Commit

Permalink
fix!: Remove ColorAuto & ColorNever settings, fixes #2811
Browse files Browse the repository at this point in the history
  • Loading branch information
pksunkara committed Oct 11, 2021
1 parent 937d76a commit b52b65b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 56 deletions.
7 changes: 3 additions & 4 deletions src/build/app/mod.rs
Expand Up @@ -2650,13 +2650,12 @@ impl<'help> App<'help> {
pub(crate) fn get_color(&self) -> ColorChoice {
debug!("App::color: Color setting...");

if self.is_set(AppSettings::ColorNever) {
debug!("Never");
ColorChoice::Never
} else if self.is_set(AppSettings::ColorAlways) {
if cfg!(feature = "color") && self.is_set(AppSettings::ColorAlways) {
debug!("Always");
ColorChoice::Always
} else {
// Same behaviour as `ColorChoice::Never` when `color` feature
// is turned off
debug!("Auto");
ColorChoice::Auto
}
Expand Down
58 changes: 6 additions & 52 deletions src/build/app/settings.rs
Expand Up @@ -26,9 +26,8 @@ bitflags! {
const NO_POS_VALUES = 1 << 17;
const NEXT_LINE_HELP = 1 << 18;
const DERIVE_DISP_ORDER = 1 << 19;
#[cfg(feature = "color")]
const COLOR_ALWAYS = 1 << 21;
const COLOR_AUTO = 1 << 22;
const COLOR_NEVER = 1 << 23;
const DONT_DELIM_TRAIL = 1 << 24;
const ALLOW_NEG_NUMS = 1 << 25;
const DISABLE_HELP_SC = 1 << 27;
Expand Down Expand Up @@ -79,12 +78,9 @@ impl_settings! { AppSettings, AppFlags,
=> Flags::ALLOW_NEG_NUMS,
AllowMissingPositional("allowmissingpositional")
=> Flags::ALLOW_MISSING_POS,
#[cfg(feature = "color")]
ColorAlways("coloralways")
=> Flags::COLOR_ALWAYS,
ColorAuto("colorauto")
=> Flags::COLOR_AUTO,
ColorNever("colornever")
=> Flags::COLOR_NEVER,
DontDelimitTrailingValues("dontdelimittrailingvalues")
=> Flags::DONT_DELIM_TRAIL,
DontCollapseArgsInUsage("dontcollapseargsinusage")
Expand Down Expand Up @@ -490,27 +486,9 @@ pub enum AppSettings {
/// ```
SubcommandPrecedenceOverArg,

/// Enables colored output only when the output is going to a terminal or TTY.
/// Enables colored output regardless of whether or not the output is going to a terminal or TTY.
///
/// **NOTE:** This is the default behavior of `clap`.
///
/// **NOTE:** Must be compiled with the `color` cargo feature.
///
/// # Platform Specific
///
/// This setting only applies to Unix, Linux, and OSX (i.e. non-Windows platforms).
///
/// # Examples
///
/// ```no_run
/// # use clap::{App, Arg, AppSettings};
/// App::new("myprog")
/// .setting(AppSettings::ColorAuto)
/// .get_matches();
/// ```
ColorAuto,

/// Enables colored output regardless of whether or not the output is going to a terminal/TTY.
/// By default, output is colored only when it is going to terminal or TTY.
///
/// **NOTE:** Must be compiled with the `color` cargo feature.
///
Expand All @@ -526,26 +504,9 @@ pub enum AppSettings {
/// .setting(AppSettings::ColorAlways)
/// .get_matches();
/// ```
#[cfg(feature = "color")]
ColorAlways,

/// Disables colored output no matter if the output is going to a terminal/TTY, or not.
///
/// **NOTE:** Must be compiled with the `color` cargo feature
///
/// # Platform Specific
///
/// This setting only applies to Unix, Linux, and OSX (i.e. non-Windows platforms)
///
/// # Examples
///
/// ```no_run
/// # use clap::{App, Arg, AppSettings};
/// App::new("myprog")
/// .setting(AppSettings::ColorNever)
/// .get_matches();
/// ```
ColorNever,

/// Disables the automatic collapsing of positional args into `[ARGS]` inside the usage string
///
/// # Examples
Expand Down Expand Up @@ -1085,18 +1046,11 @@ mod test {
"allownegativenumbers".parse::<AppSettings>().unwrap(),
AppSettings::AllowNegativeNumbers
);
assert_eq!(
"colorauto".parse::<AppSettings>().unwrap(),
AppSettings::ColorAuto
);
#[cfg(feature = "color")]
assert_eq!(
"coloralways".parse::<AppSettings>().unwrap(),
AppSettings::ColorAlways
);
assert_eq!(
"colornever".parse::<AppSettings>().unwrap(),
AppSettings::ColorNever
);
assert_eq!(
"disablehelpsubcommand".parse::<AppSettings>().unwrap(),
AppSettings::DisableHelpSubcommand
Expand Down

0 comments on commit b52b65b

Please sign in to comment.