Skip to content

Commit

Permalink
imp(AppSettings): adds ability to add multiple settings at once
Browse files Browse the repository at this point in the history
  • Loading branch information
kbknapp committed Aug 15, 2015
1 parent 3b020f9 commit 4a00e25
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ enum DidYouMeanMessageStyle {
EnumValue,
}

/// Some application options
/// Some application options
pub enum AppSettings {
/// Allows subcommands to override all requirements of the parent (this command). For example
/// if you had a subcommand or even top level application which had a required arguments that
Expand Down Expand Up @@ -685,9 +685,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
self
}

/// Enables Application Option, passed as argument
///
///
/// Enables Application level settings, passed as argument
///
/// # Example
///
Expand All @@ -698,8 +696,13 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
/// .setting(AppSettings::WaitOnError)
/// # ;
/// ```
pub fn setting(mut self, option: AppSettings) -> Self {
match option {
pub fn setting(mut self, setting: AppSettings) -> Self {
self.add_setting(&setting);
self
}

fn add_setting(&mut self, s: &AppSettings) {
match *s {
AppSettings::SubcommandsNegateReqs => self.subcmds_neg_reqs = true,
AppSettings::SubcommandRequired => self.no_sc_error = true,
AppSettings::ArgRequiredElseHelp => self.help_on_no_args = true,
Expand All @@ -709,6 +712,23 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
AppSettings::WaitOnError => self.wait_on_error = true,
AppSettings::SubcommandRequiredElseHelp => self.help_on_no_sc = true,
}
}

/// Enables multiple Application level settings, passed as argument
///
/// # Example
///
/// ```no_run
/// # use clap::{App, Arg, AppSettings};
/// App::new("myprog")
/// .settings( &[AppSettings::SubcommandRequired,
/// AppSettings::WaitOnError])
/// # ;
/// ```
pub fn settings(mut self, settings: &[AppSettings]) -> Self {
for s in settings {
self.add_setting(s);
}
self
}

Expand Down

0 comments on commit 4a00e25

Please sign in to comment.