2015-08-31 03:26:17 +00:00
|
|
|
use std::str::FromStr;
|
|
|
|
use std::ascii::AsciiExt;
|
|
|
|
|
2015-09-30 21:14:48 +00:00
|
|
|
bitflags! {
|
|
|
|
flags Flags: u32 {
|
2016-01-26 16:50:42 +00:00
|
|
|
const SC_NEGATE_REQS = 0b0000000000000000001,
|
|
|
|
const SC_REQUIRED = 0b0000000000000000010,
|
|
|
|
const A_REQUIRED_ELSE_HELP = 0b0000000000000000100,
|
|
|
|
const GLOBAL_VERSION = 0b0000000000000001000,
|
|
|
|
const VERSIONLESS_SC = 0b0000000000000010000,
|
|
|
|
const UNIFIED_HELP = 0b0000000000000100000,
|
|
|
|
const WAIT_ON_ERROR = 0b0000000000001000000,
|
|
|
|
const SC_REQUIRED_ELSE_HELP= 0b0000000000010000000,
|
|
|
|
const NEEDS_LONG_HELP = 0b0000000000100000000,
|
|
|
|
const NEEDS_LONG_VERSION = 0b0000000001000000000,
|
|
|
|
const NEEDS_SC_HELP = 0b0000000010000000000,
|
|
|
|
const DISABLE_VERSION = 0b0000000100000000000,
|
|
|
|
const HIDDEN = 0b0000001000000000000,
|
|
|
|
const TRAILING_VARARG = 0b0000010000000000000,
|
|
|
|
const NO_BIN_NAME = 0b0000100000000000000,
|
|
|
|
const ALLOW_UNK_SC = 0b0001000000000000000,
|
|
|
|
const UTF8_STRICT = 0b0010000000000000000,
|
|
|
|
const UTF8_NONE = 0b0100000000000000000,
|
|
|
|
const LEADING_HYPHEN = 0b1000000000000000000,
|
2015-09-30 21:14:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-28 13:57:47 +00:00
|
|
|
#[derive(Debug)]
|
2015-09-30 21:14:48 +00:00
|
|
|
pub struct AppFlags(Flags);
|
|
|
|
|
|
|
|
impl AppFlags {
|
|
|
|
pub fn new() -> Self {
|
2016-01-22 17:58:56 +00:00
|
|
|
AppFlags(NEEDS_LONG_VERSION | NEEDS_LONG_HELP | NEEDS_SC_HELP | UTF8_NONE)
|
2015-09-30 21:14:48 +00:00
|
|
|
}
|
|
|
|
|
2016-01-26 17:15:57 +00:00
|
|
|
impl_settings! { AppSettings,
|
|
|
|
SubcommandsNegateReqs => SC_NEGATE_REQS,
|
|
|
|
VersionlessSubcommands => VERSIONLESS_SC,
|
|
|
|
SubcommandRequired => SC_REQUIRED,
|
|
|
|
ArgRequiredElseHelp => A_REQUIRED_ELSE_HELP,
|
|
|
|
GlobalVersion => GLOBAL_VERSION,
|
|
|
|
UnifiedHelpMessage => UNIFIED_HELP,
|
|
|
|
WaitOnError => WAIT_ON_ERROR,
|
|
|
|
SubcommandRequiredElseHelp => SC_REQUIRED_ELSE_HELP,
|
|
|
|
NeedsLongHelp => NEEDS_LONG_HELP,
|
|
|
|
NeedsLongVersion => NEEDS_LONG_VERSION,
|
|
|
|
NeedsSubcommandHelp => NEEDS_SC_HELP,
|
|
|
|
DisableVersion => DISABLE_VERSION,
|
|
|
|
Hidden => HIDDEN,
|
|
|
|
TrailingVarArg => TRAILING_VARARG,
|
|
|
|
NoBinaryName => NO_BIN_NAME,
|
|
|
|
AllowExternalSubcommands => ALLOW_UNK_SC,
|
|
|
|
StrictUtf8 => UTF8_STRICT,
|
|
|
|
AllowInvalidUtf8 => UTF8_NONE,
|
|
|
|
AllowLeadingHyphen => LEADING_HYPHEN
|
2015-09-30 21:14:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-30 21:10:26 +00:00
|
|
|
/// Application level settings, which affect how `App` operates
|
2015-10-28 13:57:47 +00:00
|
|
|
#[derive(Debug, PartialEq, Copy, Clone)]
|
2015-08-30 21:10:26 +00:00
|
|
|
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
|
|
|
|
/// are only required as long as there is no subcommand present.
|
|
|
|
///
|
|
|
|
/// **NOTE:** This defaults to false (using subcommand does *not* negate requirements)
|
|
|
|
///
|
2015-09-22 02:06:15 +00:00
|
|
|
/// # Examples
|
2015-08-30 21:10:26 +00:00
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, AppSettings};
|
|
|
|
/// App::new("myprog")
|
|
|
|
/// .setting(AppSettings::SubcommandsNegateReqs)
|
|
|
|
/// # ;
|
|
|
|
/// ```
|
|
|
|
SubcommandsNegateReqs,
|
|
|
|
/// Allows specifying that if no subcommand is present at runtime, error and exit gracefully
|
|
|
|
///
|
|
|
|
/// **NOTE:** This defaults to false (subcommands do *not* need to be present)
|
|
|
|
///
|
2015-09-22 02:06:15 +00:00
|
|
|
/// # Examples
|
2015-08-30 21:10:26 +00:00
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, AppSettings};
|
|
|
|
/// App::new("myprog")
|
|
|
|
/// .setting(AppSettings::SubcommandRequired)
|
|
|
|
/// # ;
|
|
|
|
/// ```
|
|
|
|
SubcommandRequired,
|
2015-11-01 14:02:37 +00:00
|
|
|
/// Specifies that the help text should be displayed (and then exit gracefully), if no
|
2015-08-30 21:10:26 +00:00
|
|
|
/// arguments are present at runtime (i.e. an empty run such as, `$ myprog`.
|
|
|
|
///
|
|
|
|
/// **NOTE:** Subcommands count as arguments
|
|
|
|
///
|
2015-09-22 02:06:15 +00:00
|
|
|
/// # Examples
|
2015-08-30 21:10:26 +00:00
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, AppSettings};
|
|
|
|
/// App::new("myprog")
|
|
|
|
/// .setting(AppSettings::ArgRequiredElseHelp)
|
|
|
|
/// # ;
|
|
|
|
/// ```
|
|
|
|
ArgRequiredElseHelp,
|
|
|
|
/// Uses version of the current command for all subcommands. (Defaults to false; subcommands
|
|
|
|
/// have independant version strings)
|
|
|
|
///
|
|
|
|
/// **NOTE:** The version for the current command and this setting must be set **prior** to
|
|
|
|
/// adding any subcommands
|
|
|
|
///
|
2015-09-22 02:06:15 +00:00
|
|
|
/// # Examples
|
2015-08-30 21:10:26 +00:00
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg, SubCommand, AppSettings};
|
|
|
|
/// App::new("myprog")
|
|
|
|
/// .version("v1.1")
|
|
|
|
/// .setting(AppSettings::GlobalVersion)
|
|
|
|
/// .subcommand(SubCommand::with_name("test"))
|
|
|
|
/// .get_matches();
|
|
|
|
/// // running `myprog test --version` will display
|
|
|
|
/// // "myprog-test v1.1"
|
|
|
|
/// ```
|
|
|
|
GlobalVersion,
|
|
|
|
/// Disables `-V` and `--version` for all subcommands (Defaults to false; subcommands have
|
|
|
|
/// version flags)
|
|
|
|
///
|
|
|
|
/// **NOTE:** This setting must be set **prior** adding any subcommands
|
|
|
|
///
|
|
|
|
/// **NOTE:** Do not set this value to false, it will have undesired results!
|
|
|
|
///
|
2015-09-22 02:06:15 +00:00
|
|
|
/// # Examples
|
2015-08-30 21:10:26 +00:00
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg, SubCommand, AppSettings};
|
|
|
|
/// App::new("myprog")
|
|
|
|
/// .version("v1.1")
|
|
|
|
/// .setting(AppSettings::VersionlessSubcommands)
|
|
|
|
/// .subcommand(SubCommand::with_name("test"))
|
|
|
|
/// .get_matches();
|
|
|
|
/// // running `myprog test --version` will display unknown argument error
|
|
|
|
/// ```
|
|
|
|
VersionlessSubcommands,
|
|
|
|
/// By default the auto-generated help message groups flags, options, and positional arguments
|
|
|
|
/// separately. This setting disable that and groups flags and options together presenting a
|
|
|
|
/// more unified help message (a la getopts or docopt style).
|
|
|
|
///
|
|
|
|
/// **NOTE:** This setting is cosmetic only and does not affect any functionality.
|
|
|
|
///
|
2015-09-22 02:06:15 +00:00
|
|
|
/// # Examples
|
2015-08-30 21:10:26 +00:00
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg, SubCommand, AppSettings};
|
|
|
|
/// App::new("myprog")
|
|
|
|
/// .setting(AppSettings::UnifiedHelpMessage)
|
|
|
|
/// .get_matches();
|
|
|
|
/// // running `myprog --help` will display a unified "docopt" or "getopts" style help message
|
|
|
|
/// ```
|
|
|
|
UnifiedHelpMessage,
|
|
|
|
/// Will display a message "Press [ENTER]/[RETURN] to continue..." and wait user before
|
|
|
|
/// exiting
|
|
|
|
///
|
|
|
|
/// This is most useful when writing an application which is run from a GUI shortcut, or on
|
|
|
|
/// Windows where a user tries to open the binary by double-clicking instead of using the
|
|
|
|
/// command line (i.e. set `.arg_required_else_help(true)` and `.wait_on_error(true)` to
|
|
|
|
/// display the help in such a case).
|
|
|
|
///
|
|
|
|
/// **NOTE:** This setting is **not** recursive with subcommands, meaning if you wish this
|
|
|
|
/// behavior for all subcommands, you must set this on each command (needing this is extremely
|
|
|
|
/// rare)
|
|
|
|
///
|
2015-09-22 02:06:15 +00:00
|
|
|
/// # Examples
|
2015-08-30 21:10:26 +00:00
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg, AppSettings};
|
|
|
|
/// App::new("myprog")
|
|
|
|
/// .setting(AppSettings::WaitOnError)
|
|
|
|
/// # ;
|
|
|
|
/// ```
|
|
|
|
WaitOnError,
|
2015-11-01 14:02:37 +00:00
|
|
|
/// Specifies that the help text should be displayed (and then exit gracefully), if no
|
2015-08-30 21:10:26 +00:00
|
|
|
/// subcommands are present at runtime (i.e. an empty run such as, `$ myprog`.
|
|
|
|
///
|
|
|
|
/// **NOTE:** This should *not* be used with `.subcommand_required()` as they do the same
|
|
|
|
/// thing, except one prints the help text, and one prints an error.
|
|
|
|
///
|
|
|
|
/// **NOTE:** If the user specifies arguments at runtime, but no subcommand the help text will
|
|
|
|
/// still be displayed and exit. If this is *not* the desired result, consider using
|
|
|
|
/// `.arg_required_else_help()`
|
|
|
|
///
|
2015-09-22 02:06:15 +00:00
|
|
|
/// # Examples
|
2015-08-30 21:10:26 +00:00
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg, AppSettings};
|
|
|
|
/// App::new("myprog")
|
|
|
|
/// .setting(AppSettings::SubcommandRequiredElseHelp)
|
|
|
|
/// # ;
|
|
|
|
/// ```
|
|
|
|
SubcommandRequiredElseHelp,
|
2015-10-01 01:41:40 +00:00
|
|
|
/// Specifies that this subcommand should be hidden from help messages
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg, AppSettings, SubCommand};
|
|
|
|
/// App::new("myprog")
|
|
|
|
/// .subcommand(SubCommand::with_name("test")
|
2015-10-28 14:23:59 +00:00
|
|
|
/// .setting(AppSettings::Hidden))
|
2015-10-01 01:41:40 +00:00
|
|
|
/// # ;
|
|
|
|
/// ```
|
|
|
|
Hidden,
|
2015-10-01 18:16:13 +00:00
|
|
|
/// Specifies that the final positional argument is a vararg and that `clap` should not attempt
|
|
|
|
/// to parse any further args.
|
|
|
|
///
|
|
|
|
/// The values of the trailing positional argument will contain all args from itself on.
|
|
|
|
///
|
|
|
|
/// **NOTE:** The final positional argument **must** have `.multiple(true)` or usage token
|
2015-11-01 14:02:37 +00:00
|
|
|
/// equivalent.
|
2015-10-01 18:16:13 +00:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg, AppSettings};
|
|
|
|
/// let m = App::new("myprog")
|
|
|
|
/// .setting(AppSettings::TrailingVarArg)
|
|
|
|
/// .arg(Arg::from_usage("<cmd>... 'commands to run'"))
|
2016-01-22 04:18:52 +00:00
|
|
|
/// .get_matches_from(vec!["myprog", "some_command", "-r", "set"]);
|
2015-10-01 18:16:13 +00:00
|
|
|
///
|
2016-01-22 04:18:52 +00:00
|
|
|
/// assert_eq!(m.values_of("cmd").unwrap().collect::<Vec<_>>(), &["some_command", "-r", "set"]);
|
2015-10-01 18:16:13 +00:00
|
|
|
/// ```
|
|
|
|
TrailingVarArg,
|
2015-10-28 10:45:45 +00:00
|
|
|
/// Specifies that the parser should not assume the first argument passed is the binary name.
|
|
|
|
/// This is normally the case when using a "daemon" style mode, or an interactive CLI where one
|
|
|
|
/// one would not normally type the binary or program name for each command.
|
|
|
|
///
|
|
|
|
/// **NOTE:** This should only be used when you absolutely know it's what you need. 99% of the
|
|
|
|
/// cases out there don't need this setting.
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg, AppSettings};
|
|
|
|
/// let m = App::new("myprog")
|
|
|
|
/// .setting(AppSettings::NoBinaryName)
|
|
|
|
/// .arg(Arg::from_usage("<cmd>... 'commands to run'"))
|
|
|
|
/// .get_matches_from(vec!["some_command", "-r", "set"]);
|
|
|
|
///
|
2016-01-22 04:18:52 +00:00
|
|
|
/// assert_eq!(m.values_of("cmd").unwrap().collect::<Vec<_>>(), &["some_command", "-r", "set"]);
|
2015-10-28 10:45:45 +00:00
|
|
|
/// ```
|
|
|
|
NoBinaryName,
|
2016-01-11 08:59:56 +00:00
|
|
|
/// Specifies that an unexpected argument positional arguments which would otherwise cause a
|
2016-01-22 04:18:52 +00:00
|
|
|
/// `ErrorKind::UnknownArgument` error, should instead be treated as a subcommand in the
|
2016-01-11 08:59:56 +00:00
|
|
|
/// `ArgMatches` struct.
|
|
|
|
///
|
|
|
|
/// **NOTE:** Use this setting with caution, as a truly unexpected argument (i.e. one that is
|
2016-01-22 04:18:52 +00:00
|
|
|
/// *NOT* an external subcommand) will not cause an error and instead be treatd as a potential
|
|
|
|
/// subcommand. You shoud inform the user appropriatly.
|
2016-01-11 08:59:56 +00:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
feat: adds support for external subcommands
External subcommands are now supported via the following:
```rust
extern crate clap;
use clap::{App, AppSettings};
fn main() {
// Assume there is a third party subcommand named myprog-subcmd
let m = App::new("myprog")
.setting(AppSettings::AllowExternalSubcommands)
.get_matches_from(vec![
"myprog", "subcmd", "--option", "value", "-fff", "--flag"
]);
// All trailing arguments will be stored under the subcommands sub-matches under a
// value of their runtime name (in this case "subcmd")
match m.subcommand() {
(external, Some(ext_m)) => {
let ext_args: Vec<&str> = ext_m.values_of(external).unwrap().collect();
assert_eq!(ext_args ,["--option", "value", "-fff", "--flag"]);
},
_ => unreachable!()
}
}
```
Closes #372
2016-01-26 17:25:56 +00:00
|
|
|
/// # use clap::{App, AppSettings};
|
2016-01-22 04:18:52 +00:00
|
|
|
/// // Assume there is a third party subcommand named myprog-subcmd
|
2016-01-11 08:59:56 +00:00
|
|
|
/// let m = App::new("myprog")
|
|
|
|
/// .setting(AppSettings::AllowExternalSubcommands)
|
feat: adds support for external subcommands
External subcommands are now supported via the following:
```rust
extern crate clap;
use clap::{App, AppSettings};
fn main() {
// Assume there is a third party subcommand named myprog-subcmd
let m = App::new("myprog")
.setting(AppSettings::AllowExternalSubcommands)
.get_matches_from(vec![
"myprog", "subcmd", "--option", "value", "-fff", "--flag"
]);
// All trailing arguments will be stored under the subcommands sub-matches under a
// value of their runtime name (in this case "subcmd")
match m.subcommand() {
(external, Some(ext_m)) => {
let ext_args: Vec<&str> = ext_m.values_of(external).unwrap().collect();
assert_eq!(ext_args ,["--option", "value", "-fff", "--flag"]);
},
_ => unreachable!()
}
}
```
Closes #372
2016-01-26 17:25:56 +00:00
|
|
|
/// .get_matches_from(vec![
|
|
|
|
/// "myprog", "subcmd", "--option", "value", "-fff", "--flag"
|
|
|
|
/// ]);
|
2016-01-22 04:18:52 +00:00
|
|
|
/// // All trailing arguments will be stored under the subcommands sub-matches under a value
|
|
|
|
/// // of their runtime name (in this case "subcmd")
|
2016-01-11 08:59:56 +00:00
|
|
|
/// match m.subcommand() {
|
2016-01-22 04:18:52 +00:00
|
|
|
/// (external, Some(ext_m)) => {
|
feat: adds support for external subcommands
External subcommands are now supported via the following:
```rust
extern crate clap;
use clap::{App, AppSettings};
fn main() {
// Assume there is a third party subcommand named myprog-subcmd
let m = App::new("myprog")
.setting(AppSettings::AllowExternalSubcommands)
.get_matches_from(vec![
"myprog", "subcmd", "--option", "value", "-fff", "--flag"
]);
// All trailing arguments will be stored under the subcommands sub-matches under a
// value of their runtime name (in this case "subcmd")
match m.subcommand() {
(external, Some(ext_m)) => {
let ext_args: Vec<&str> = ext_m.values_of(external).unwrap().collect();
assert_eq!(ext_args ,["--option", "value", "-fff", "--flag"]);
},
_ => unreachable!()
}
}
```
Closes #372
2016-01-26 17:25:56 +00:00
|
|
|
/// let ext_args: Vec<&str> = ext_m.values_of(external).unwrap().collect();
|
|
|
|
/// assert_eq!(ext_args, ["--option", "value", "-fff", "--flag"]);
|
2016-01-11 08:59:56 +00:00
|
|
|
/// },
|
|
|
|
/// _ => unreachable!()
|
|
|
|
/// }
|
|
|
|
/// ```
|
|
|
|
AllowExternalSubcommands,
|
2016-01-22 17:58:56 +00:00
|
|
|
/// Specifies that any invalid UTF-8 code points should be treated as an error and fail
|
|
|
|
/// with a `ErrorKind::InvalidUtf8` error.
|
|
|
|
///
|
|
|
|
/// **NOTE:** This rule only applies to argument values, as flags, options, and subcommands
|
|
|
|
/// only allow valid UTF-8 code points.
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```ignore
|
|
|
|
/// # use clap::{App, Arg, AppSettings, ErrorKind};
|
|
|
|
/// use std::ffi::OsString;
|
|
|
|
///
|
|
|
|
/// let m = App::new("myprog")
|
|
|
|
/// .setting(AppSettings::StrictUtf8)
|
|
|
|
/// .arg_from_usage("<arg> 'some positional arg'")
|
|
|
|
/// .get_matches_from_safe(
|
|
|
|
/// vec![
|
|
|
|
/// OsString::from("myprog"),
|
|
|
|
/// OsString::from_vec(vec![0xe9])]);
|
|
|
|
///
|
|
|
|
/// assert!(m.is_err());
|
|
|
|
/// assert_eq!(m.unwrap_err().kind, ErrorKind::InvalidUtf8);
|
|
|
|
/// }
|
|
|
|
/// ```
|
2016-01-11 08:59:56 +00:00
|
|
|
StrictUtf8,
|
2016-01-22 17:58:56 +00:00
|
|
|
/// Specifies that any invalid UTF-8 code points should *not* be treated as an error. This is
|
|
|
|
/// the default behavior of `clap`
|
|
|
|
///
|
|
|
|
/// **NOTE:** Using argument values with invalid UTF-8 code points requires using Either
|
|
|
|
/// `ArgMatches::os_value(s)_of` or `ArgMatches::lossy_value(s)_of` for those particular
|
|
|
|
/// arguments which may have have invalid UTF-8 values
|
|
|
|
///
|
|
|
|
/// **NOTE:** This rule only applies to argument values, as flags, options, and subcommands
|
|
|
|
/// only allow valid UTF-8 code points.
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```ignore
|
|
|
|
/// # use clap::{App, Arg, AppSettings};
|
|
|
|
/// use std::ffi::OsString;
|
|
|
|
/// use std::os::unix::ffi::OsStrExt;
|
|
|
|
///
|
|
|
|
/// let r = App::new("myprog")
|
|
|
|
/// .setting(AppSettings::StrictUtf8)
|
|
|
|
/// .arg_from_usage("<arg> 'some positional arg'")
|
|
|
|
/// .get_matches_from_safe(
|
|
|
|
/// vec![
|
|
|
|
/// OsString::from("myprog"),
|
|
|
|
/// OsString::from_vec(vec![0xe9])]);
|
|
|
|
///
|
|
|
|
/// assert!(r.is_ok());
|
|
|
|
/// let m = r.unwrap();
|
|
|
|
/// assert_eq!(m.os_value_of("arg").unwrap().as_bytes(), &[0xe9]);
|
|
|
|
/// ```
|
2016-01-11 08:59:56 +00:00
|
|
|
AllowInvalidUtf8,
|
2016-01-26 16:50:42 +00:00
|
|
|
/// Specifies whether or not leading hyphens are allowed in argument values, such as `-10`
|
|
|
|
///
|
|
|
|
/// **NOTE:** This can only be set application wide
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{Arg, App, AppSettings};
|
|
|
|
/// // Imagine you needed to represent negative numbers as well, such as -10
|
|
|
|
/// let m = App::new("nums")
|
|
|
|
/// .setting(AppSettings::AllowLeadingHyphen)
|
|
|
|
/// .arg(Arg::with_name("neg"))
|
|
|
|
/// .get_matches_from(vec![
|
|
|
|
/// "nums", "-20"
|
|
|
|
/// ]);
|
|
|
|
///
|
|
|
|
/// assert_eq!(m.value_of("neg"), Some("-20"));
|
|
|
|
/// # ;
|
|
|
|
AllowLeadingHyphen,
|
2015-09-30 21:14:48 +00:00
|
|
|
#[doc(hidden)]
|
|
|
|
NeedsLongVersion,
|
|
|
|
#[doc(hidden)]
|
|
|
|
NeedsLongHelp,
|
|
|
|
#[doc(hidden)]
|
|
|
|
NeedsSubcommandHelp,
|
|
|
|
#[doc(hidden)]
|
|
|
|
DisableVersion,
|
2015-08-31 03:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl FromStr for AppSettings {
|
|
|
|
type Err = String;
|
|
|
|
fn from_str(s: &str) -> Result<Self, <Self as FromStr>::Err> {
|
|
|
|
match &*s.to_ascii_lowercase() {
|
2015-10-28 14:23:59 +00:00
|
|
|
"subcommandsnegatereqs" => Ok(AppSettings::SubcommandsNegateReqs),
|
|
|
|
"subcommandsrequired" => Ok(AppSettings::SubcommandRequired),
|
|
|
|
"argrequiredelsehelp" => Ok(AppSettings::ArgRequiredElseHelp),
|
|
|
|
"globalversion" => Ok(AppSettings::GlobalVersion),
|
2015-08-31 03:26:17 +00:00
|
|
|
"versionlesssubcommands" => Ok(AppSettings::VersionlessSubcommands),
|
2015-10-28 14:23:59 +00:00
|
|
|
"unifiedhelpmessage" => Ok(AppSettings::UnifiedHelpMessage),
|
|
|
|
"waitonerror" => Ok(AppSettings::WaitOnError),
|
2015-08-31 03:26:17 +00:00
|
|
|
"subcommandrequiredelsehelp" => Ok(AppSettings::SubcommandRequiredElseHelp),
|
2015-10-28 14:23:59 +00:00
|
|
|
"hidden" => Ok(AppSettings::Hidden),
|
2016-01-11 08:59:56 +00:00
|
|
|
"AllowExternalSubcommands" => Ok(AppSettings::AllowExternalSubcommands),
|
|
|
|
"trailingvararg" => Ok(AppSettings::TrailingVarArg),
|
|
|
|
"nobinaryname" => Ok(AppSettings::NoBinaryName),
|
|
|
|
"allowexternalsubcommands" => Ok(AppSettings::AllowExternalSubcommands),
|
|
|
|
"strictutf8" => Ok(AppSettings::StrictUtf8),
|
|
|
|
"allowinvalidutf8" => Ok(AppSettings::AllowInvalidUtf8),
|
2016-01-26 16:50:42 +00:00
|
|
|
"allowleadinghyphen" => Ok(AppSettings::AllowLeadingHyphen),
|
2015-10-28 14:23:59 +00:00
|
|
|
_ => Err("unknown AppSetting, cannot convert from str".to_owned()),
|
2015-08-31 03:26:17 +00:00
|
|
|
}
|
|
|
|
}
|
2015-09-07 01:07:46 +00:00
|
|
|
}
|