mirror of
https://github.com/clap-rs/clap
synced 2024-11-12 23:57:10 +00:00
feat(Settings): Add unset_setting and unset_settings fns to App (#598)
Closes #590.
This commit is contained in:
parent
84a08758b2
commit
0ceba231c6
2 changed files with 62 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue