Skip to content

Commit

Permalink
feat(Settings): Add unset_setting and unset_settings fns to App (#598)
Browse files Browse the repository at this point in the history
Closes #590.
  • Loading branch information
Barret Rennie authored and kbknapp committed Jul 24, 2016
1 parent 84a0875 commit 0ceba23
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions tests/app_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,24 @@ fn leading_double_hyphen_trailingvararg() {
assert!(m.is_present("opt"));
assert_eq!(m.values_of("opt").unwrap().collect::<Vec<_>>(), &["--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));
}

0 comments on commit 0ceba23

Please sign in to comment.