2016-09-05 21:03:45 +00:00
|
|
|
// Std
|
2015-08-31 03:26:17 +00:00
|
|
|
use std::ascii::AsciiExt;
|
2016-09-05 19:29:40 +00:00
|
|
|
use std::str::FromStr;
|
2015-08-31 03:26:17 +00:00
|
|
|
|
2015-09-30 21:14:48 +00:00
|
|
|
bitflags! {
|
|
|
|
flags Flags: u32 {
|
2016-06-05 05:09:07 +00:00
|
|
|
const SC_NEGATE_REQS = 0b000000000000000000000000001,
|
|
|
|
const SC_REQUIRED = 0b000000000000000000000000010,
|
|
|
|
const A_REQUIRED_ELSE_HELP = 0b000000000000000000000000100,
|
|
|
|
const GLOBAL_VERSION = 0b000000000000000000000001000,
|
|
|
|
const VERSIONLESS_SC = 0b000000000000000000000010000,
|
|
|
|
const UNIFIED_HELP = 0b000000000000000000000100000,
|
|
|
|
const WAIT_ON_ERROR = 0b000000000000000000001000000,
|
|
|
|
const SC_REQUIRED_ELSE_HELP= 0b000000000000000000010000000,
|
|
|
|
const NEEDS_LONG_HELP = 0b000000000000000000100000000,
|
|
|
|
const NEEDS_LONG_VERSION = 0b000000000000000001000000000,
|
|
|
|
const NEEDS_SC_HELP = 0b000000000000000010000000000,
|
|
|
|
const DISABLE_VERSION = 0b000000000000000100000000000,
|
|
|
|
const HIDDEN = 0b000000000000001000000000000,
|
|
|
|
const TRAILING_VARARG = 0b000000000000010000000000000,
|
|
|
|
const NO_BIN_NAME = 0b000000000000100000000000000,
|
|
|
|
const ALLOW_UNK_SC = 0b000000000001000000000000000,
|
|
|
|
const UTF8_STRICT = 0b000000000010000000000000000,
|
|
|
|
const UTF8_NONE = 0b000000000100000000000000000,
|
|
|
|
const LEADING_HYPHEN = 0b000000001000000000000000000,
|
|
|
|
const NO_POS_VALUES = 0b000000010000000000000000000,
|
|
|
|
const NEXT_LINE_HELP = 0b000000100000000000000000000,
|
|
|
|
const DERIVE_DISP_ORDER = 0b000001000000000000000000000,
|
|
|
|
const COLORED_HELP = 0b000010000000000000000000000,
|
|
|
|
const COLOR_ALWAYS = 0b000100000000000000000000000,
|
|
|
|
const COLOR_AUTO = 0b001000000000000000000000000,
|
|
|
|
const COLOR_NEVER = 0b010000000000000000000000000,
|
|
|
|
const DONT_DELIM_TRAIL = 0b100000000000000000000000000,
|
2015-09-30 21:14:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-26 19:02:10 +00:00
|
|
|
#[doc(hidden)]
|
2015-10-28 13:57:47 +00:00
|
|
|
#[derive(Debug)]
|
2015-09-30 21:14:48 +00:00
|
|
|
pub struct AppFlags(Flags);
|
|
|
|
|
2016-03-15 02:09:17 +00:00
|
|
|
impl Clone for AppFlags {
|
|
|
|
fn clone(&self) -> Self {
|
|
|
|
AppFlags(self.0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-09 22:35:40 +00:00
|
|
|
impl Default for AppFlags {
|
|
|
|
fn default() -> Self {
|
2016-05-30 08:07:44 +00:00
|
|
|
AppFlags(NEEDS_LONG_VERSION | NEEDS_LONG_HELP | NEEDS_SC_HELP | UTF8_NONE | COLOR_AUTO)
|
2016-03-09 22:35:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-30 21:14:48 +00:00
|
|
|
impl AppFlags {
|
|
|
|
pub fn new() -> Self {
|
2016-03-09 22:35:40 +00:00
|
|
|
AppFlags::default()
|
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,
|
2016-02-02 08:13:18 +00:00
|
|
|
AllowLeadingHyphen => LEADING_HYPHEN,
|
2016-02-17 07:54:25 +00:00
|
|
|
HidePossibleValuesInHelp => NO_POS_VALUES,
|
2016-03-10 21:31:59 +00:00
|
|
|
NextLineHelp => NEXT_LINE_HELP,
|
2016-04-18 06:45:44 +00:00
|
|
|
ColoredHelp => COLORED_HELP,
|
2016-05-30 08:07:44 +00:00
|
|
|
DeriveDisplayOrder => DERIVE_DISP_ORDER,
|
|
|
|
ColorAlways => COLOR_ALWAYS,
|
|
|
|
ColorAuto => COLOR_AUTO,
|
2016-06-05 05:09:07 +00:00
|
|
|
ColorNever => COLOR_NEVER,
|
|
|
|
DontDelimitTrailingValues => DONT_DELIM_TRAIL
|
2015-09-30 21:14:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-14 20:25:00 +00:00
|
|
|
/// Application level settings, which affect how [`App`] operates
|
2016-02-19 05:08:13 +00:00
|
|
|
///
|
|
|
|
/// **NOTE:** When these settings are used, they apply only to current command, and are *not*
|
|
|
|
/// propagated down or up through child or parent subcommands
|
2016-05-14 20:25:00 +00:00
|
|
|
///
|
|
|
|
/// [`App`]: ./struct.App.html
|
2015-10-28 13:57:47 +00:00
|
|
|
#[derive(Debug, PartialEq, Copy, Clone)]
|
2015-08-30 21:10:26 +00:00
|
|
|
pub enum AppSettings {
|
2016-05-14 20:25:00 +00:00
|
|
|
/// Allows [`SubCommand`]s to override all requirements of the parent command. For example if you
|
|
|
|
/// had a subcommand or top level application which had a required argument that are only
|
|
|
|
/// required as long as there is no subcommand present, using this setting would allow you set
|
|
|
|
/// those arguments to [`Arg::required(true)`] and yet receive no error so long as the user
|
2016-01-26 19:02:10 +00:00
|
|
|
/// uses a valid subcommand instead.
|
2015-08-30 21:10:26 +00:00
|
|
|
///
|
|
|
|
/// **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
|
|
|
///
|
2016-01-26 19:02:10 +00:00
|
|
|
/// This first example shows that it is an error to not use a required argument
|
|
|
|
///
|
|
|
|
/// ```rust
|
|
|
|
/// # use clap::{App, Arg, AppSettings, SubCommand, ErrorKind};
|
|
|
|
/// let err = App::new("myprog")
|
|
|
|
/// .setting(AppSettings::SubcommandsNegateReqs)
|
|
|
|
/// .arg(Arg::with_name("opt").required(true))
|
|
|
|
/// .subcommand(SubCommand::with_name("test"))
|
|
|
|
/// .get_matches_from_safe(vec![
|
|
|
|
/// "myprog"
|
|
|
|
/// ]);
|
|
|
|
/// assert!(err.is_err());
|
|
|
|
/// assert_eq!(err.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
|
|
|
|
/// # ;
|
|
|
|
/// ```
|
|
|
|
///
|
|
|
|
/// This next example shows that it is no longer error to not use a required argument if a
|
|
|
|
/// valid subcommand is used.
|
|
|
|
///
|
|
|
|
/// ```rust
|
|
|
|
/// # use clap::{App, Arg, AppSettings, SubCommand, ErrorKind};
|
|
|
|
/// let noerr = App::new("myprog")
|
2015-08-30 21:10:26 +00:00
|
|
|
/// .setting(AppSettings::SubcommandsNegateReqs)
|
2016-01-26 19:02:10 +00:00
|
|
|
/// .arg(Arg::with_name("opt").required(true))
|
|
|
|
/// .subcommand(SubCommand::with_name("test"))
|
|
|
|
/// .get_matches_from_safe(vec![
|
|
|
|
/// "myprog", "test"
|
|
|
|
/// ]);
|
|
|
|
/// assert!(noerr.is_ok());
|
2015-08-30 21:10:26 +00:00
|
|
|
/// # ;
|
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`Arg::required(true)`]: ./struct.Arg.html#method.required
|
|
|
|
/// [`SubCommand`]: ./struct.SubCommand.html
|
2015-08-30 21:10:26 +00:00
|
|
|
SubcommandsNegateReqs,
|
2016-05-14 20:25:00 +00:00
|
|
|
/// Allows specifying that if no [`SubCommand`] is present at runtime, error and exit
|
|
|
|
/// gracefully
|
2015-08-30 21:10:26 +00:00
|
|
|
///
|
2016-05-14 20:25:00 +00:00
|
|
|
/// **NOTE:** This defaults to `false` (subcommands do *not* need to be present)
|
2015-08-30 21:10:26 +00:00
|
|
|
///
|
2015-09-22 02:06:15 +00:00
|
|
|
/// # Examples
|
2015-08-30 21:10:26 +00:00
|
|
|
///
|
2016-01-26 19:02:10 +00:00
|
|
|
/// ```rust
|
|
|
|
/// # use clap::{App, AppSettings, SubCommand, ErrorKind};
|
|
|
|
/// let err = App::new("myprog")
|
2015-08-30 21:10:26 +00:00
|
|
|
/// .setting(AppSettings::SubcommandRequired)
|
2016-01-26 19:02:10 +00:00
|
|
|
/// .subcommand(SubCommand::with_name("test"))
|
|
|
|
/// .get_matches_from_safe(vec![
|
|
|
|
/// "myprog",
|
|
|
|
/// ]);
|
|
|
|
/// assert!(err.is_err());
|
|
|
|
/// assert_eq!(err.unwrap_err().kind, ErrorKind::MissingSubcommand);
|
2015-08-30 21:10:26 +00:00
|
|
|
/// # ;
|
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`SubCommand`]: ./struct.SubCommand.html
|
2015-08-30 21:10:26 +00:00
|
|
|
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`.
|
|
|
|
///
|
2016-05-14 20:25:00 +00:00
|
|
|
/// **NOTE:** [`SubCommand`]s count as arguments
|
2015-08-30 21:10:26 +00:00
|
|
|
///
|
2015-09-22 02:06:15 +00:00
|
|
|
/// # Examples
|
2015-08-30 21:10:26 +00:00
|
|
|
///
|
2016-01-26 19:02:10 +00:00
|
|
|
/// ```rust
|
2015-08-30 21:10:26 +00:00
|
|
|
/// # use clap::{App, AppSettings};
|
|
|
|
/// App::new("myprog")
|
|
|
|
/// .setting(AppSettings::ArgRequiredElseHelp)
|
|
|
|
/// # ;
|
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`SubCommand`]: ./struct.SubCommand.html
|
2015-08-30 21:10:26 +00:00
|
|
|
ArgRequiredElseHelp,
|
2016-05-14 20:25:00 +00:00
|
|
|
/// Specifies to use the version of the current command for all child [`SubCommand`]. (Defaults
|
|
|
|
/// to `false`; subcommands have independant version strings from their parents)
|
2015-08-30 21:10:26 +00:00
|
|
|
///
|
2016-01-26 19:02:10 +00:00
|
|
|
/// **NOTE:** The version for the current command **and** this setting must be set **prior** to
|
|
|
|
/// adding any child subcommands
|
2015-08-30 21:10:26 +00:00
|
|
|
///
|
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();
|
2016-01-26 19:02:10 +00:00
|
|
|
/// // running `$ myprog test --version` will display
|
2015-08-30 21:10:26 +00:00
|
|
|
/// // "myprog-test v1.1"
|
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`SubCommand`]: ./struct.SubCommand.html
|
2015-08-30 21:10:26 +00:00
|
|
|
GlobalVersion,
|
2016-05-14 20:25:00 +00:00
|
|
|
/// Disables `-V` and `--version` for all [`SubCommand`]s (Defaults to `false`; subcommands
|
|
|
|
/// *do* have version flags)
|
2015-08-30 21:10:26 +00:00
|
|
|
///
|
|
|
|
/// **NOTE:** This setting must be set **prior** adding any subcommands
|
|
|
|
///
|
2015-09-22 02:06:15 +00:00
|
|
|
/// # Examples
|
2015-08-30 21:10:26 +00:00
|
|
|
///
|
2016-01-26 19:02:10 +00:00
|
|
|
/// ```rust
|
|
|
|
/// # use clap::{App, SubCommand, AppSettings, ErrorKind};
|
|
|
|
/// let res = App::new("myprog")
|
2015-08-30 21:10:26 +00:00
|
|
|
/// .version("v1.1")
|
|
|
|
/// .setting(AppSettings::VersionlessSubcommands)
|
|
|
|
/// .subcommand(SubCommand::with_name("test"))
|
2016-01-26 19:02:10 +00:00
|
|
|
/// .get_matches_from_safe(vec![
|
|
|
|
/// "myprog", "test", "-V"
|
|
|
|
/// ]);
|
|
|
|
/// assert!(res.is_err());
|
|
|
|
/// assert_eq!(res.unwrap_err().kind, ErrorKind::UnknownArgument);
|
2015-08-30 21:10:26 +00:00
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`SubCommand`]: ./struct.SubCommand.html
|
2015-08-30 21:10:26 +00:00
|
|
|
VersionlessSubcommands,
|
2016-01-26 19:02:10 +00:00
|
|
|
/// Groups flags and options together presenting a more unified help message (a la `getopts` or
|
2016-05-14 20:25:00 +00:00
|
|
|
/// `docopt` style).
|
|
|
|
///
|
|
|
|
/// The default is that the auto-generated help message will group flags, and options
|
2016-01-26 19:02:10 +00:00
|
|
|
/// separately.
|
2015-08-30 21:10:26 +00:00
|
|
|
///
|
|
|
|
/// **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,
|
2016-06-24 10:23:08 +00:00
|
|
|
/// Will display a message "Press [ENTER]/[RETURN] to continue..." and wait for user before
|
2015-08-30 21:10:26 +00:00
|
|
|
/// 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
|
2016-01-26 19:02:10 +00:00
|
|
|
/// command line.
|
2015-08-30 21:10:26 +00:00
|
|
|
///
|
2016-05-14 20:25:00 +00:00
|
|
|
/// **NOTE:** This setting is **not** recursive with [`SubCommand`]s, meaning if you wish this
|
2015-08-30 21:10:26 +00:00
|
|
|
/// 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
|
|
|
///
|
2016-01-26 19:02:10 +00:00
|
|
|
/// ```rust
|
2015-08-30 21:10:26 +00:00
|
|
|
/// # use clap::{App, Arg, AppSettings};
|
|
|
|
/// App::new("myprog")
|
|
|
|
/// .setting(AppSettings::WaitOnError)
|
|
|
|
/// # ;
|
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`SubCommand`]: ./struct.SubCommand.html
|
2015-08-30 21:10:26 +00:00
|
|
|
WaitOnError,
|
2015-11-01 14:02:37 +00:00
|
|
|
/// Specifies that the help text should be displayed (and then exit gracefully), if no
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`SubCommand`]s are present at runtime (i.e. an empty run such as, `$ myprog`.
|
2015-08-30 21:10:26 +00:00
|
|
|
///
|
2016-05-14 20:25:00 +00:00
|
|
|
/// **NOTE:** This should *not* be used with [`AppSettings::SubcommandRequired`] as they do
|
|
|
|
/// nearly same thing; this prints the help text, and the other prints an error.
|
2015-08-30 21:10:26 +00:00
|
|
|
///
|
|
|
|
/// **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
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`AppSettings::ArgRequiredElseHelp`] instead.
|
2015-08-30 21:10:26 +00:00
|
|
|
///
|
2015-09-22 02:06:15 +00:00
|
|
|
/// # Examples
|
2015-08-30 21:10:26 +00:00
|
|
|
///
|
2016-01-26 19:02:10 +00:00
|
|
|
/// ```rust
|
2015-08-30 21:10:26 +00:00
|
|
|
/// # use clap::{App, Arg, AppSettings};
|
|
|
|
/// App::new("myprog")
|
|
|
|
/// .setting(AppSettings::SubcommandRequiredElseHelp)
|
|
|
|
/// # ;
|
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`SubCommand`]: ./struct.SubCommand.html
|
|
|
|
/// [`AppSettings::SubcommandRequired`]: ./enum.AppSettings.html#variant.SubcommandRequired
|
|
|
|
/// [`AppSettings::ArgRequiredElseHelp`]: ./enum.AppSettings.html#variant.ArgRequiredElseHelp
|
2015-08-30 21:10:26 +00:00
|
|
|
SubcommandRequiredElseHelp,
|
2016-05-14 20:25:00 +00:00
|
|
|
/// Specifies that this [`SubCommand`] should be hidden from help messages
|
2015-10-01 01:41:40 +00:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
2016-01-26 19:02:10 +00:00
|
|
|
/// ```rust
|
2015-10-01 01:41:40 +00:00
|
|
|
/// # 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
|
|
|
/// # ;
|
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`SubCommand`]: ./struct.SubCommand.html
|
2015-10-01 01:41:40 +00:00
|
|
|
Hidden,
|
2016-01-26 19:02:10 +00:00
|
|
|
/// Specifies that the final positional argument is a "VarArg" and that `clap` should not
|
|
|
|
/// attempt to parse any further args.
|
2015-10-01 18:16:13 +00:00
|
|
|
///
|
|
|
|
/// The values of the trailing positional argument will contain all args from itself on.
|
|
|
|
///
|
2016-05-14 20:25:00 +00:00
|
|
|
/// **NOTE:** The final positional argument **must** have [`Arg::multiple(true)`] or the usage
|
|
|
|
/// string equivalent.
|
2015-10-01 18:16:13 +00:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
2016-01-26 19:02:10 +00:00
|
|
|
/// ```rust
|
2015-10-01 18:16:13 +00:00
|
|
|
/// # use clap::{App, Arg, AppSettings};
|
|
|
|
/// let m = App::new("myprog")
|
|
|
|
/// .setting(AppSettings::TrailingVarArg)
|
|
|
|
/// .arg(Arg::from_usage("<cmd>... 'commands to run'"))
|
2016-01-26 19:02:10 +00:00
|
|
|
/// .get_matches_from(vec!["myprog", "arg1", "-r", "val1"]);
|
2015-10-01 18:16:13 +00:00
|
|
|
///
|
2016-01-26 19:02:10 +00:00
|
|
|
/// let trail: Vec<&str> = m.values_of("cmd").unwrap().collect();
|
|
|
|
/// assert_eq!(trail, ["arg1", "-r", "val1"]);
|
2015-10-01 18:16:13 +00:00
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`Arg::multiple(true)`]: ./struct.Arg.html#method.multiple
|
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.
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
2016-01-26 19:02:10 +00:00
|
|
|
/// ```rust
|
2015-10-28 10:45:45 +00:00
|
|
|
/// # use clap::{App, Arg, AppSettings};
|
|
|
|
/// let m = App::new("myprog")
|
|
|
|
/// .setting(AppSettings::NoBinaryName)
|
|
|
|
/// .arg(Arg::from_usage("<cmd>... 'commands to run'"))
|
2016-01-26 19:02:10 +00:00
|
|
|
/// .get_matches_from(vec!["command", "set"]);
|
2015-10-28 10:45:45 +00:00
|
|
|
///
|
2016-01-26 19:02:10 +00:00
|
|
|
/// let cmds: Vec<&str> = m.values_of("cmd").unwrap().collect();
|
|
|
|
/// assert_eq!(cmds, ["command", "set"]);
|
2015-10-28 10:45:45 +00:00
|
|
|
/// ```
|
|
|
|
NoBinaryName,
|
2016-05-14 20:25:00 +00:00
|
|
|
/// Specifies that an unexpected positional argument, which would otherwise cause a
|
|
|
|
/// [`ErrorKind::UnknownArgument`] error, should instead be treated as a [`SubCommand`] within
|
|
|
|
/// the [`ArgMatches`] struct.
|
2016-01-11 08:59:56 +00:00
|
|
|
///
|
|
|
|
/// **NOTE:** Use this setting with caution, as a truly unexpected argument (i.e. one that is
|
2016-06-24 10:23:08 +00:00
|
|
|
/// *NOT* an external subcommand) will **not** cause an error and instead be treated as a
|
2016-05-14 20:25:00 +00:00
|
|
|
/// potential subcommand. One should check for such cases manually and inform the user
|
2016-06-24 10:23:08 +00:00
|
|
|
/// appropriately.
|
2016-01-11 08:59:56 +00:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
2016-01-26 19:02:10 +00:00
|
|
|
/// ```rust
|
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-26 19:02:10 +00:00
|
|
|
/// // Assume there is an external subcommand named "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-26 19:02:10 +00:00
|
|
|
///
|
2016-07-16 21:18:46 +00:00
|
|
|
/// // All trailing arguments will be stored under the subcommand's sub-matches using an empty
|
|
|
|
/// // string argument name
|
2016-01-11 08:59:56 +00:00
|
|
|
/// match m.subcommand() {
|
2016-01-22 04:18:52 +00:00
|
|
|
/// (external, Some(ext_m)) => {
|
2016-07-16 21:18:46 +00:00
|
|
|
/// let ext_args: Vec<&str> = ext_m.values_of("").unwrap().collect();
|
|
|
|
/// assert_eq!(external, "subcmd");
|
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
|
|
|
/// assert_eq!(ext_args, ["--option", "value", "-fff", "--flag"]);
|
2016-01-11 08:59:56 +00:00
|
|
|
/// },
|
2016-01-26 19:02:10 +00:00
|
|
|
/// _ => {},
|
2016-01-11 08:59:56 +00:00
|
|
|
/// }
|
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`ErrorKind::UnknownArgument`]: ./enum.ErrorKind.html#variant.UnknownArgument
|
|
|
|
/// [`SubCommand`]: ./struct.SubCommand.html
|
|
|
|
/// [`ArgMatches`]: ./struct.ArgMatches.html
|
2016-01-11 08:59:56 +00:00
|
|
|
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
|
2016-05-14 20:25:00 +00:00
|
|
|
/// with a [`ErrorKind::InvalidUtf8`] error.
|
2016-01-22 17:58:56 +00:00
|
|
|
///
|
2016-05-14 20:25:00 +00:00
|
|
|
/// **NOTE:** This rule only applies to argument values. Things such as flags, options, and
|
|
|
|
/// [`SubCommand`]s themselves only allow valid UTF-8 code points.
|
2016-01-26 19:02:10 +00:00
|
|
|
///
|
|
|
|
/// # Platform Specific
|
|
|
|
///
|
|
|
|
/// Non Windows systems only
|
2016-01-22 17:58:56 +00:00
|
|
|
///
|
|
|
|
/// # 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-05-14 20:25:00 +00:00
|
|
|
/// [`SubCommand`]: ./struct.SubCommand.html
|
|
|
|
/// [`ErrorKind::InvalidUtf8`]: ./enum.ErrorKind.html#variant.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`
|
|
|
|
///
|
2016-05-14 20:25:00 +00:00
|
|
|
/// **NOTE:** Using argument values with invalid UTF-8 code points requires using
|
|
|
|
/// [`ArgMatches::os_value_of`], [`ArgMatches::os_values_of`], [`ArgMatches::lossy_value_of`],
|
|
|
|
/// or [`ArgMatches::lossy_values_of`] for those particular arguments which may contain invalid
|
|
|
|
/// UTF-8 values
|
2016-01-22 17:58:56 +00:00
|
|
|
///
|
2016-05-14 20:25:00 +00:00
|
|
|
/// **NOTE:** This rule only applies to argument values, as flags, options, and
|
|
|
|
/// [`SubCommand`]s themselves only allow valid UTF-8 code points.
|
2016-01-26 19:02:10 +00:00
|
|
|
///
|
|
|
|
/// # Platform Specific
|
|
|
|
///
|
|
|
|
/// Non Windows systems only
|
2016-01-22 17:58:56 +00:00
|
|
|
///
|
|
|
|
/// # 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();
|
2016-01-29 02:51:50 +00:00
|
|
|
/// assert_eq!(m.value_of_os("arg").unwrap().as_bytes(), &[0xe9]);
|
2016-01-22 17:58:56 +00:00
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`ArgMatches::os_value_of`]: ./struct.ArgMatches.html#method.os_value_of
|
|
|
|
/// [`ArgMatches::os_values_of`]: ./struct.ArgMatches.html#method.os_values_of
|
|
|
|
/// [`ArgMatches::lossy_value_of`]: ./struct.ArgMatches.html#method.lossy_value_of
|
|
|
|
/// [`ArgMatches::lossy_values_of`]: ./struct.ArgMatches.html#method.lossy_values_of
|
2016-01-11 08:59:56 +00:00
|
|
|
AllowInvalidUtf8,
|
2016-02-19 05:08:13 +00:00
|
|
|
/// Specifies that leading hyphens are allowed in argument *values*, such as negative numbers
|
2016-05-14 20:25:00 +00:00
|
|
|
/// `-10` (which would otherwise be parsed as another flag or option)
|
2016-01-26 16:50:42 +00:00
|
|
|
///
|
2016-01-26 19:02:10 +00:00
|
|
|
/// **NOTE:** This can only be set application wide and not on a per argument basis.
|
|
|
|
///
|
|
|
|
/// **NOTE:** Use this setting with caution as it silences certain circumstances which would
|
|
|
|
/// otherwise be an error (such as accidentally forgetting to specify a value for leading
|
|
|
|
/// option)
|
2016-01-26 16:50:42 +00:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
2016-01-26 19:02:10 +00:00
|
|
|
/// ```rust
|
2016-01-26 16:50:42 +00:00
|
|
|
/// # 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)
|
2016-01-27 16:28:52 +00:00
|
|
|
/// .arg(Arg::with_name("neg").index(1))
|
2016-01-26 16:50:42 +00:00
|
|
|
/// .get_matches_from(vec![
|
|
|
|
/// "nums", "-20"
|
|
|
|
/// ]);
|
|
|
|
///
|
|
|
|
/// assert_eq!(m.value_of("neg"), Some("-20"));
|
|
|
|
/// # ;
|
2016-01-26 19:02:10 +00:00
|
|
|
/// ```
|
2016-01-26 16:50:42 +00:00
|
|
|
AllowLeadingHyphen,
|
2016-02-17 07:54:25 +00:00
|
|
|
/// Tells `clap` *not* to print possible values when displaying help information. This can be
|
2016-02-02 08:13:18 +00:00
|
|
|
/// useful if there are many values, or they are explained elsewhere.
|
|
|
|
HidePossibleValuesInHelp,
|
2016-02-17 07:54:25 +00:00
|
|
|
/// Places the help string for all arguments on the line after the argument
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg, SubCommand, AppSettings};
|
|
|
|
/// App::new("myprog")
|
|
|
|
/// .setting(AppSettings::NextLineHelp)
|
|
|
|
/// .get_matches();
|
|
|
|
/// ```
|
|
|
|
NextLineHelp,
|
2016-05-14 20:25:00 +00:00
|
|
|
/// Displays the arguments and [`SubCommand`]s in the help message in the order that they were
|
2016-03-10 21:31:59 +00:00
|
|
|
/// declared in, vice alphabetically which is the default.
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg, SubCommand, AppSettings};
|
|
|
|
/// App::new("myprog")
|
|
|
|
/// .setting(AppSettings::DeriveDisplayOrder)
|
|
|
|
/// .get_matches();
|
|
|
|
/// ```
|
2016-05-14 20:25:00 +00:00
|
|
|
/// [`SubCommand`]: ./struct.SubCommand.html
|
2016-03-10 21:31:59 +00:00
|
|
|
DeriveDisplayOrder,
|
2016-04-18 06:45:44 +00:00
|
|
|
/// Uses colorized help messages.
|
|
|
|
///
|
|
|
|
/// **NOTE:** Must be compiled with the `color` cargo feature
|
|
|
|
///
|
|
|
|
/// # Platform Specific
|
|
|
|
///
|
|
|
|
/// This setting only applies to Unix, Linux, and OSX (i.e. non-Windows platforms)
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg, SubCommand, AppSettings};
|
|
|
|
/// App::new("myprog")
|
|
|
|
/// .setting(AppSettings::ColoredHelp)
|
|
|
|
/// .get_matches();
|
|
|
|
/// ```
|
|
|
|
ColoredHelp,
|
2016-05-30 08:07:44 +00:00
|
|
|
/// Enables colored output only when the output is going to a terminal or TTY.
|
|
|
|
///
|
|
|
|
/// **NOTE:** This is the default behavior of `clap`
|
|
|
|
///
|
|
|
|
/// **NOTE:** Must be compiled with the `color` cargo feature
|
|
|
|
///
|
|
|
|
/// # Platform Specific
|
|
|
|
///
|
|
|
|
/// This setting only applies to Unix, Linux, and OSX (i.e. non-Windows platforms)
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg, SubCommand, AppSettings};
|
|
|
|
/// App::new("myprog")
|
|
|
|
/// .setting(AppSettings::ColorAuto)
|
|
|
|
/// .get_matches();
|
|
|
|
/// ```
|
|
|
|
ColorAuto,
|
|
|
|
/// Enables colored output regardless of whether or not the output is going to a terminal/TTY.
|
|
|
|
///
|
|
|
|
/// **NOTE:** Must be compiled with the `color` cargo feature
|
|
|
|
///
|
|
|
|
/// # Platform Specific
|
|
|
|
///
|
|
|
|
/// This setting only applies to Unix, Linux, and OSX (i.e. non-Windows platforms)
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg, SubCommand, AppSettings};
|
|
|
|
/// App::new("myprog")
|
|
|
|
/// .setting(AppSettings::ColorAlways)
|
|
|
|
/// .get_matches();
|
|
|
|
/// ```
|
|
|
|
ColorAlways,
|
|
|
|
/// Disables colored output no matter if the output is going to a terminal/TTY, or not.
|
|
|
|
///
|
|
|
|
/// **NOTE:** Must be compiled with the `color` cargo feature
|
|
|
|
///
|
|
|
|
/// # Platform Specific
|
|
|
|
///
|
|
|
|
/// This setting only applies to Unix, Linux, and OSX (i.e. non-Windows platforms)
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg, SubCommand, AppSettings};
|
|
|
|
/// App::new("myprog")
|
|
|
|
/// .setting(AppSettings::ColorNever)
|
|
|
|
/// .get_matches();
|
|
|
|
/// ```
|
|
|
|
ColorNever,
|
2016-06-05 05:09:07 +00:00
|
|
|
/// Disables the automatic delimiting of values when `--` or [`AppSettings::TrailingVarArg`]
|
|
|
|
/// was used.
|
|
|
|
///
|
|
|
|
/// **NOTE:** The same thing can be done manually by setting the final positional argument to
|
|
|
|
/// [`Arg::use_delimiter(false)`]. Using this setting is safer, because it's easier to locate
|
|
|
|
/// when making changes.
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// # use clap::{App, Arg, SubCommand, AppSettings};
|
|
|
|
/// App::new("myprog")
|
|
|
|
/// .setting(AppSettings::DontDelimitTrailingValues)
|
|
|
|
/// .get_matches();
|
|
|
|
/// ```
|
|
|
|
/// [`AppSettings::TrailingVarArg`]: ./enum.AppSettings.html#variant.TrailingVarArg
|
|
|
|
/// [`Arg::use_delimiter(false)`]: ./struct.Arg.html#method.use_delimiter
|
|
|
|
DontDelimitTrailingValues,
|
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),
|
2016-07-23 20:23:48 +00:00
|
|
|
"subcommandrequired" => Ok(AppSettings::SubcommandRequired),
|
2015-10-28 14:23:59 +00:00
|
|
|
"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-26 19:02:10 +00:00
|
|
|
"allowexternalsubcommands" => Ok(AppSettings::AllowExternalSubcommands),
|
2016-01-11 08:59:56 +00:00
|
|
|
"trailingvararg" => Ok(AppSettings::TrailingVarArg),
|
|
|
|
"nobinaryname" => Ok(AppSettings::NoBinaryName),
|
|
|
|
"strictutf8" => Ok(AppSettings::StrictUtf8),
|
|
|
|
"allowinvalidutf8" => Ok(AppSettings::AllowInvalidUtf8),
|
2016-01-26 16:50:42 +00:00
|
|
|
"allowleadinghyphen" => Ok(AppSettings::AllowLeadingHyphen),
|
2016-02-02 08:13:18 +00:00
|
|
|
"hidepossiblevaluesinhelp" => Ok(AppSettings::HidePossibleValuesInHelp),
|
2016-02-17 07:54:25 +00:00
|
|
|
"nextlinehelp" => Ok(AppSettings::NextLineHelp),
|
2016-03-10 21:31:59 +00:00
|
|
|
"derivedisplayorder" => Ok(AppSettings::DeriveDisplayOrder),
|
2016-04-18 06:45:44 +00:00
|
|
|
"coloredhelp" => Ok(AppSettings::ColoredHelp),
|
2016-06-05 05:07:47 +00:00
|
|
|
"dontdelimittrailingvalues" => Ok(AppSettings::DontDelimitTrailingValues),
|
|
|
|
"colorauto" => Ok(AppSettings::ColorAuto),
|
|
|
|
"coloralways" => Ok(AppSettings::ColorAlways),
|
|
|
|
"colornever" => Ok(AppSettings::ColorNever),
|
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
|
|
|
}
|
2016-03-14 01:33:03 +00:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
use super::AppSettings;
|
2016-03-15 02:09:17 +00:00
|
|
|
|
2016-03-14 01:33:03 +00:00
|
|
|
#[test]
|
|
|
|
fn app_settings_fromstr() {
|
2016-05-06 21:35:53 +00:00
|
|
|
assert_eq!("subcommandsnegatereqs".parse::<AppSettings>().unwrap(),
|
|
|
|
AppSettings::SubcommandsNegateReqs);
|
2016-07-23 20:23:48 +00:00
|
|
|
assert_eq!("subcommandrequired".parse::<AppSettings>().unwrap(),
|
2016-05-06 21:35:53 +00:00
|
|
|
AppSettings::SubcommandRequired);
|
|
|
|
assert_eq!("argrequiredelsehelp".parse::<AppSettings>().unwrap(),
|
|
|
|
AppSettings::ArgRequiredElseHelp);
|
|
|
|
assert_eq!("globalversion".parse::<AppSettings>().unwrap(),
|
|
|
|
AppSettings::GlobalVersion);
|
|
|
|
assert_eq!("versionlesssubcommands".parse::<AppSettings>().unwrap(),
|
|
|
|
AppSettings::VersionlessSubcommands);
|
|
|
|
assert_eq!("unifiedhelpmessage".parse::<AppSettings>().unwrap(),
|
|
|
|
AppSettings::UnifiedHelpMessage);
|
|
|
|
assert_eq!("waitonerror".parse::<AppSettings>().unwrap(),
|
|
|
|
AppSettings::WaitOnError);
|
|
|
|
assert_eq!("subcommandrequiredelsehelp".parse::<AppSettings>().unwrap(),
|
|
|
|
AppSettings::SubcommandRequiredElseHelp);
|
|
|
|
assert_eq!("allowexternalsubcommands".parse::<AppSettings>().unwrap(),
|
|
|
|
AppSettings::AllowExternalSubcommands);
|
|
|
|
assert_eq!("trailingvararg".parse::<AppSettings>().unwrap(),
|
|
|
|
AppSettings::TrailingVarArg);
|
|
|
|
assert_eq!("nobinaryname".parse::<AppSettings>().unwrap(),
|
|
|
|
AppSettings::NoBinaryName);
|
|
|
|
assert_eq!("strictutf8".parse::<AppSettings>().unwrap(),
|
|
|
|
AppSettings::StrictUtf8);
|
|
|
|
assert_eq!("allowinvalidutf8".parse::<AppSettings>().unwrap(),
|
|
|
|
AppSettings::AllowInvalidUtf8);
|
|
|
|
assert_eq!("allowleadinghyphen".parse::<AppSettings>().unwrap(),
|
|
|
|
AppSettings::AllowLeadingHyphen);
|
|
|
|
assert_eq!("hidepossiblevaluesinhelp".parse::<AppSettings>().unwrap(),
|
|
|
|
AppSettings::HidePossibleValuesInHelp);
|
|
|
|
assert_eq!("coloredhelp".parse::<AppSettings>().unwrap(),
|
|
|
|
AppSettings::ColoredHelp);
|
|
|
|
assert_eq!("hidden".parse::<AppSettings>().unwrap(),
|
|
|
|
AppSettings::Hidden);
|
2016-06-05 05:09:07 +00:00
|
|
|
assert_eq!("dontdelimittrailingvalues".parse::<AppSettings>().unwrap(),
|
2016-09-05 19:29:40 +00:00
|
|
|
AppSettings::DontDelimitTrailingValues);
|
2016-03-14 01:33:03 +00:00
|
|
|
assert!("hahahaha".parse::<AppSettings>().is_err());
|
|
|
|
}
|
|
|
|
}
|