Skip to content

Commit

Permalink
fix(app): Propogate color
Browse files Browse the repository at this point in the history
In clap-rs#2851, we moved color from an AppSetting to function (with some
tweaks in clap-rs#2907).  When doing this, we documented `App::color` to be
equivalent of `App::global_settings(Color...)` but never actually
propagated it.

We are now propagating it.  A test is added to ensure that no matter
how we store the color choice, we continue to propagate it.  This
required exposing `App::get_color`.
  • Loading branch information
epage committed Nov 11, 2021
1 parent ae67496 commit a2c3b14
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/build/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,9 +1045,9 @@ impl<'help> App<'help> {
pub fn color(self, color: ColorChoice) -> Self {
#[allow(deprecated)]
match color {
ColorChoice::Auto => self.setting(AppSettings::ColorAuto),
ColorChoice::Always => self.setting(AppSettings::ColorAlways),
ColorChoice::Never => self.setting(AppSettings::ColorNever),
ColorChoice::Auto => self.global_setting(AppSettings::ColorAuto),
ColorChoice::Always => self.global_setting(AppSettings::ColorAlways),
ColorChoice::Never => self.global_setting(AppSettings::ColorNever),
}
}

Expand Down
13 changes: 13 additions & 0 deletions tests/app_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1216,3 +1216,16 @@ fn no_auto_version_mut_arg() {
assert!(result.is_ok());
assert!(result.unwrap().is_present("version"));
}

#[test]
#[cfg(feature = "color")]
fn color_is_global() {
let mut app = App::new("myprog")
.color(clap::ColorChoice::Never)
.subcommand(App::new("foo"));
app._build_all();
assert_eq!(app.get_color(), clap::ColorChoice::Never);

let sub = app.get_subcommands().collect::<Vec<_>>()[0];
assert_eq!(sub.get_color(), clap::ColorChoice::Never);
}

0 comments on commit a2c3b14

Please sign in to comment.