diff --git a/src/app/mod.rs b/src/app/mod.rs index 7446b97b9c9..4458d72a582 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -484,6 +484,47 @@ impl<'a, 'b> App<'a, 'b> { self } + /// Disables a single command, or [`SubCommand`], level setting. + /// + /// See [`AppSettings`] for a full list of possibilities and examples. + /// + /// # Examples + /// + /// ```no_run + /// # use clap::{App, AppSettings}; + /// App::new("myprog") + /// .unset_setting(AppSettings::ColorAuto) + /// # ; + /// ``` + /// [`SubCommand`]: ./struct.SubCommand.html + /// [`AppSettings`]: ./enum.AppSettings.html + pub fn unset_setting(mut self, setting: AppSettings) -> Self { + self.p.unset(setting); + self + } + + /// Disables multiple command, or [`SubCommand`], level settings. + /// + /// See [`AppSettings`] for a full list of possibilities and examples. + /// + /// # Examples + /// + /// ```no_run + /// # use clap::{App, AppSettings}; + /// App::new("myprog") + /// .unset_settings(&[AppSettings::ColorAuto, + /// AppSettings::AllowInvalidUtf8]) + /// # ; + /// ``` + /// [`SubCommand`]: ./struct.SubCommand.html + /// [`AppSettings`]: ./enum.AppSettings.html + pub fn unset_settings(mut self, settings: &[AppSettings]) -> Self { + for s in settings { + self.p.unset(*s); + } + self + } + /// Sets the terminal width at which to wrap help messages. Defaults to `120`. /// /// `clap` automatically tries to determine the terminal width on Unix, Linux, and OSX if the diff --git a/tests/app_settings.rs b/tests/app_settings.rs index 24d4ebf0862..54911b18677 100644 --- a/tests/app_settings.rs +++ b/tests/app_settings.rs @@ -247,3 +247,24 @@ fn leading_double_hyphen_trailingvararg() { assert!(m.is_present("opt")); assert_eq!(m.values_of("opt").unwrap().collect::>(), &["--foo", "-Wl", "bar"]); } + +#[test] +fn test_unset_setting() { + let m = App::new("unset_setting"); + assert!(m.p.is_set(AppSettings::AllowInvalidUtf8)); + + let m = m.unset_setting(AppSettings::AllowInvalidUtf8); + assert!(!m.p.is_set(AppSettings::AllowInvalidUtf8)); +} + +#[test] +fn test_unset_settings() { + let m = App::new("unset_settings"); + assert!(&m.p.is_set(AppSettings::AllowInvalidUtf8)); + assert!(&m.p.is_set(AppSettings::ColorAuto)); + + let m = m.unset_settings(&[AppSettings::AllowInvalidUtf8, + AppSettings::ColorAuto]); + assert!(!m.p.is_set(AppSettings::AllowInvalidUtf8)); + assert!(!m.p.is_set(AppSettings::ColorAuto)); +}