feat: Replace application level settings with enum variants

This commit is contained in:
Alexander Kuvaev 2015-08-15 00:14:59 +03:00
parent 23aca97072
commit 618dc4e2c2

View file

@ -53,6 +53,18 @@ enum DidYouMeanMessageStyle {
EnumValue,
}
/// Some application options
pub enum AppOptions {
SubcommandsNagateReqs,
SubcommandRequired,
ArgRequiredElseHelp,
GlobalVersion,
VersionlessSubcommands,
UnifiedHelpMessage,
WaitOnError,
SubcommandRequiredElseHelp,
}
/// Used to create a representation of a command line program and all possible command line
/// arguments.
///
@ -545,6 +557,31 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
self
}
/// Enables Application Option, passed as argument
///
/// # Example
///
/// ```no_run
/// # use clap::{App, Arg};
/// App::new("myprog")
/// .setting(AppOptions::SubcommandRequired)
/// .setting(AppOptions::WaitOnError)
/// # ;
/// ```
pub fn setting(mut self, option: AppOptions) -> Self {
match option {
AppOptions::SubcommandsNagateReqs => self.subcmds_neg_reqs = true,
AppOptions::SubcommandRequired => self.no_sc_error = true,
AppOptions::ArgRequiredElseHelp => self.help_on_no_args = true,
AppOptions::GlobalVersion => self.global_ver = true,
AppOptions::VersionlessSubcommands => self.versionless_scs = Some(true),
AppOptions::UnifiedHelpMessage => self.unified_help = true,
AppOptions::WaitOnError => self.wait_on_error = true,
AppOptions::SubcommandRequiredElseHelp => self.help_on_no_sc = true,
}
self
}
/// Adds an argument to the list of valid possibilties manually. This method allows you full
/// control over the arguments settings and options (as well as dynamic generation). It also
/// allows you specify several more advanced configuration options such as relational rules