Skip to content

Commit 0ceba23

Browse files
brenniekbknapp
authored andcommitted
feat(Settings): Add unset_setting and unset_settings fns to App (#598)
Closes #590.
1 parent 84a0875 commit 0ceba23

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

src/app/mod.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,47 @@ impl<'a, 'b> App<'a, 'b> {
484484
self
485485
}
486486

487+
/// Disables a single command, or [`SubCommand`], level setting.
488+
///
489+
/// See [`AppSettings`] for a full list of possibilities and examples.
490+
///
491+
/// # Examples
492+
///
493+
/// ```no_run
494+
/// # use clap::{App, AppSettings};
495+
/// App::new("myprog")
496+
/// .unset_setting(AppSettings::ColorAuto)
497+
/// # ;
498+
/// ```
499+
/// [`SubCommand`]: ./struct.SubCommand.html
500+
/// [`AppSettings`]: ./enum.AppSettings.html
501+
pub fn unset_setting(mut self, setting: AppSettings) -> Self {
502+
self.p.unset(setting);
503+
self
504+
}
505+
506+
/// Disables multiple command, or [`SubCommand`], level settings.
507+
///
508+
/// See [`AppSettings`] for a full list of possibilities and examples.
509+
///
510+
/// # Examples
511+
///
512+
/// ```no_run
513+
/// # use clap::{App, AppSettings};
514+
/// App::new("myprog")
515+
/// .unset_settings(&[AppSettings::ColorAuto,
516+
/// AppSettings::AllowInvalidUtf8])
517+
/// # ;
518+
/// ```
519+
/// [`SubCommand`]: ./struct.SubCommand.html
520+
/// [`AppSettings`]: ./enum.AppSettings.html
521+
pub fn unset_settings(mut self, settings: &[AppSettings]) -> Self {
522+
for s in settings {
523+
self.p.unset(*s);
524+
}
525+
self
526+
}
527+
487528
/// Sets the terminal width at which to wrap help messages. Defaults to `120`.
488529
///
489530
/// `clap` automatically tries to determine the terminal width on Unix, Linux, and OSX if the

tests/app_settings.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,24 @@ fn leading_double_hyphen_trailingvararg() {
247247
assert!(m.is_present("opt"));
248248
assert_eq!(m.values_of("opt").unwrap().collect::<Vec<_>>(), &["--foo", "-Wl", "bar"]);
249249
}
250+
251+
#[test]
252+
fn test_unset_setting() {
253+
let m = App::new("unset_setting");
254+
assert!(m.p.is_set(AppSettings::AllowInvalidUtf8));
255+
256+
let m = m.unset_setting(AppSettings::AllowInvalidUtf8);
257+
assert!(!m.p.is_set(AppSettings::AllowInvalidUtf8));
258+
}
259+
260+
#[test]
261+
fn test_unset_settings() {
262+
let m = App::new("unset_settings");
263+
assert!(&m.p.is_set(AppSettings::AllowInvalidUtf8));
264+
assert!(&m.p.is_set(AppSettings::ColorAuto));
265+
266+
let m = m.unset_settings(&[AppSettings::AllowInvalidUtf8,
267+
AppSettings::ColorAuto]);
268+
assert!(!m.p.is_set(AppSettings::AllowInvalidUtf8));
269+
assert!(!m.p.is_set(AppSettings::ColorAuto));
270+
}

0 commit comments

Comments
 (0)