mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 23:04:23 +00:00
feat: Replace application level settings with enum variants
This commit is contained in:
parent
23aca97072
commit
618dc4e2c2
1 changed files with 37 additions and 0 deletions
37
src/app.rs
37
src/app.rs
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue