Enum pretty_exec::structopt_utilities::structopt::clap::ErrorKind [−][src]
pub enum ErrorKind {
Show variants
InvalidValue,
UnknownArgument,
InvalidSubcommand,
UnrecognizedSubcommand,
EmptyValue,
ValueValidation,
TooManyValues,
TooFewValues,
WrongNumberOfValues,
ArgumentConflict,
MissingRequiredArgument,
MissingSubcommand,
MissingArgumentOrSubcommand,
UnexpectedMultipleUsage,
InvalidUtf8,
HelpDisplayed,
VersionDisplayed,
ArgumentNotFound,
Io,
Format,
}Expand description
Command line argument parser kind of error
Variants
Occurs when an Arg has a set of possible values,
and the user provides a value which isn’t in that set.
Examples
let result = App::new("prog") .arg(Arg::with_name("speed") .possible_value("fast") .possible_value("slow")) .get_matches_from_safe(vec!["prog", "other"]); assert!(result.is_err()); assert_eq!(result.unwrap_err().kind, ErrorKind::InvalidValue);
Occurs when a user provides a flag, option, argument or subcommand which isn’t defined.
Examples
let result = App::new("prog") .arg(Arg::from_usage("--flag 'some flag'")) .get_matches_from_safe(vec!["prog", "--other"]); assert!(result.is_err()); assert_eq!(result.unwrap_err().kind, ErrorKind::UnknownArgument);
Occurs when the user provides an unrecognized SubCommand which meets the threshold for
being similar enough to an existing subcommand.
If it doesn’t meet the threshold, or the ‘suggestions’ feature is disabled,
the more general UnknownArgument error is returned.
Examples
let result = App::new("prog") .subcommand(SubCommand::with_name("config") .about("Used for configuration") .arg(Arg::with_name("config_file") .help("The configuration file to use") .index(1))) .get_matches_from_safe(vec!["prog", "confi"]); assert!(result.is_err()); assert_eq!(result.unwrap_err().kind, ErrorKind::InvalidSubcommand);
Occurs when the user provides an unrecognized SubCommand which either
doesn’t meet the threshold for being similar enough to an existing subcommand,
or the ‘suggestions’ feature is disabled.
Otherwise the more detailed InvalidSubcommand error is returned.
This error typically happens when passing additional subcommand names to the help
subcommand. Otherwise, the more general UnknownArgument error is used.
Examples
let result = App::new("prog") .subcommand(SubCommand::with_name("config") .about("Used for configuration") .arg(Arg::with_name("config_file") .help("The configuration file to use") .index(1))) .get_matches_from_safe(vec!["prog", "help", "nothing"]); assert!(result.is_err()); assert_eq!(result.unwrap_err().kind, ErrorKind::UnrecognizedSubcommand);
Occurs when the user provides an empty value for an option that does not allow empty values.
Examples
let res = App::new("prog") .arg(Arg::with_name("color") .long("color") .empty_values(false)) .get_matches_from_safe(vec!["prog", "--color="]); assert!(res.is_err()); assert_eq!(res.unwrap_err().kind, ErrorKind::EmptyValue);
Occurs when the user provides a value for an argument with a custom validation and the value fails that validation.
Examples
fn is_numeric(val: String) -> Result<(), String> { match val.parse::<i64>() { Ok(..) => Ok(()), Err(..) => Err(String::from("Value wasn't a number!")), } } let result = App::new("prog") .arg(Arg::with_name("num") .validator(is_numeric)) .get_matches_from_safe(vec!["prog", "NotANumber"]); assert!(result.is_err()); assert_eq!(result.unwrap_err().kind, ErrorKind::ValueValidation);
Occurs when a user provides more values for an argument than were defined by setting
Arg::max_values.
Examples
let result = App::new("prog") .arg(Arg::with_name("arg") .multiple(true) .max_values(2)) .get_matches_from_safe(vec!["prog", "too", "many", "values"]); assert!(result.is_err()); assert_eq!(result.unwrap_err().kind, ErrorKind::TooManyValues);
Occurs when the user provides fewer values for an argument than were defined by setting
Arg::min_values.
Examples
let result = App::new("prog") .arg(Arg::with_name("some_opt") .long("opt") .min_values(3)) .get_matches_from_safe(vec!["prog", "--opt", "too", "few"]); assert!(result.is_err()); assert_eq!(result.unwrap_err().kind, ErrorKind::TooFewValues);
Occurs when the user provides a different number of values for an argument than what’s
been defined by setting Arg::number_of_values or than was implicitly set by
Arg::value_names.
Examples
let result = App::new("prog") .arg(Arg::with_name("some_opt") .long("opt") .takes_value(true) .number_of_values(2)) .get_matches_from_safe(vec!["prog", "--opt", "wrong"]); assert!(result.is_err()); assert_eq!(result.unwrap_err().kind, ErrorKind::WrongNumberOfValues);
Occurs when the user provides two values which conflict with each other and can’t be used together.
Examples
let result = App::new("prog") .arg(Arg::with_name("debug") .long("debug") .conflicts_with("color")) .arg(Arg::with_name("color") .long("color")) .get_matches_from_safe(vec!["prog", "--debug", "--color"]); assert!(result.is_err()); assert_eq!(result.unwrap_err().kind, ErrorKind::ArgumentConflict);
Occurs when the user does not provide one or more required arguments.
Examples
let result = App::new("prog") .arg(Arg::with_name("debug") .required(true)) .get_matches_from_safe(vec!["prog"]); assert!(result.is_err()); assert_eq!(result.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
Occurs when a subcommand is required (as defined by AppSettings::SubcommandRequired),
but the user does not provide one.
Examples
let err = App::new("prog") .setting(AppSettings::SubcommandRequired) .subcommand(SubCommand::with_name("test")) .get_matches_from_safe(vec![ "myprog", ]); assert!(err.is_err()); assert_eq!(err.unwrap_err().kind, ErrorKind::MissingSubcommand);
Occurs when either an argument or SubCommand is required, as defined by
AppSettings::ArgRequiredElseHelp, but the user did not provide one.
Examples
let result = App::new("prog") .setting(AppSettings::ArgRequiredElseHelp) .subcommand(SubCommand::with_name("config") .about("Used for configuration") .arg(Arg::with_name("config_file") .help("The configuration file to use"))) .get_matches_from_safe(vec!["prog"]); assert!(result.is_err()); assert_eq!(result.unwrap_err().kind, ErrorKind::MissingArgumentOrSubcommand);
Occurs when the user provides multiple values to an argument which doesn’t allow that.
Examples
let result = App::new("prog") .arg(Arg::with_name("debug") .long("debug") .multiple(false)) .get_matches_from_safe(vec!["prog", "--debug", "--debug"]); assert!(result.is_err()); assert_eq!(result.unwrap_err().kind, ErrorKind::UnexpectedMultipleUsage);
Occurs when the user provides a value containing invalid UTF-8 for an argument and
AppSettings::StrictUtf8 is set.
Platform Specific
Non-Windows platforms only (such as Linux, Unix, macOS, etc.)
Examples
let result = App::new("prog") .setting(AppSettings::StrictUtf8) .arg(Arg::with_name("utf8") .short("u") .takes_value(true)) .get_matches_from_safe(vec![OsString::from("myprog"), OsString::from("-u"), OsString::from_vec(vec![0xE9])]); assert!(result.is_err()); assert_eq!(result.unwrap_err().kind, ErrorKind::InvalidUtf8);
Not a true “error” as it means --help or similar was used.
The help message will be sent to stdout.
Note: If the help is displayed due to an error (such as missing subcommands) it will
be sent to stderr instead of stdout.
Examples
let result = App::new("prog") .get_matches_from_safe(vec!["prog", "--help"]); assert!(result.is_err()); assert_eq!(result.unwrap_err().kind, ErrorKind::HelpDisplayed);
Not a true “error” as it means --version or similar was used.
The message will be sent to stdout.
Examples
let result = App::new("prog") .get_matches_from_safe(vec!["prog", "--version"]); assert!(result.is_err()); assert_eq!(result.unwrap_err().kind, ErrorKind::VersionDisplayed);
Occurs when using the [value_t!] and [values_t!] macros to convert an argument value
into type T, but the argument you requested wasn’t used. I.e. you asked for an argument
with name config to be converted, but config wasn’t used by the user.
[value_t!]: ./macro.value_t!.html
[values_t!]: ./macro.values_t!.html
Represents an [I/O error].
Can occur when writing to stderr or stdout or reading a configuration file.
[I/O error]: https://doc.rust-lang.org/std/io/struct.Error.html
Represents a Format error (which is a part of Display).
Typically caused by writing to stderr or stdout.
Trait Implementations
impl Copy for ErrorKind[src]
impl StructuralPartialEq for ErrorKind[src]
Auto Trait Implementations
impl RefUnwindSafe for ErrorKind
impl Send for ErrorKind
impl Sync for ErrorKind
impl Unpin for ErrorKind
impl UnwindSafe for ErrorKind
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]pub fn borrow_mut(&mut self) -> &mut T[src]
pub fn borrow_mut(&mut self) -> &mut T[src]Mutably borrows from an owned value. Read more
impl<X> Pipe for X
impl<X> Pipe for Ximpl<X> Pipe for X
impl<X> Pipe for Xfn pipe<Return, Function>(self, f: Function) -> Return where
Function: FnOnce(Self) -> Return,
fn pipe<Return, Function>(self, f: Function) -> Return where
Function: FnOnce(Self) -> Return, Apply f to self. Read more
fn pipe_ref<'a, Return, Function>(&'a self, f: Function) -> Return where
Function: FnOnce(&'a Self) -> Return,
fn pipe_ref<'a, Return, Function>(&'a self, f: Function) -> Return where
Function: FnOnce(&'a Self) -> Return, Apply f to &self. Read more
fn pipe_mut<'a, Return, Function>(&'a mut self, f: Function) -> Return where
Function: FnOnce(&'a mut Self) -> Return,
fn pipe_mut<'a, Return, Function>(&'a mut self, f: Function) -> Return where
Function: FnOnce(&'a mut Self) -> Return, Apply f to &mut self. Read more
fn pipe_as_ref<'a, Param, Return, Function>(&'a self, f: Function) -> Return where
Self: AsRef<Param>,
Param: 'a + ?Sized,
Function: FnOnce(&'a Param) -> Return,
fn pipe_as_ref<'a, Param, Return, Function>(&'a self, f: Function) -> Return where
Self: AsRef<Param>,
Param: 'a + ?Sized,
Function: FnOnce(&'a Param) -> Return, Apply f to &self where f takes a single parameter of type Param
and Self implements trait AsRef<Param>. Read more
fn pipe_as_mut<'a, Param, Return, Function>(&'a mut self, f: Function) -> Return where
Self: AsMut<Param>,
Param: 'a + ?Sized,
Function: FnOnce(&'a mut Param) -> Return,
fn pipe_as_mut<'a, Param, Return, Function>(&'a mut self, f: Function) -> Return where
Self: AsMut<Param>,
Param: 'a + ?Sized,
Function: FnOnce(&'a mut Param) -> Return, Apply f to &mut self where f takes a single parameter of type Param
and Self implements trait AsMut<Param>. Read more
fn pipe_deref<'a, Param, Return, Function>(&'a self, f: Function) -> Return where
Self: Deref<Target = Param>,
Param: 'a + ?Sized,
Function: FnOnce(&'a Param) -> Return,
fn pipe_deref<'a, Param, Return, Function>(&'a self, f: Function) -> Return where
Self: Deref<Target = Param>,
Param: 'a + ?Sized,
Function: FnOnce(&'a Param) -> Return, Apply f to &self where f takes a single parameter of type Param
and Self implements trait Deref<Param>. Read more
fn pipe_deref_mut<'a, Param, Return, Function>(
&'a mut self,
f: Function
) -> Return where
Self: DerefMut<Target = Param>,
Param: 'a + ?Sized,
Function: FnOnce(&'a mut Param) -> Return,
fn pipe_deref_mut<'a, Param, Return, Function>(
&'a mut self,
f: Function
) -> Return where
Self: DerefMut<Target = Param>,
Param: 'a + ?Sized,
Function: FnOnce(&'a mut Param) -> Return, Apply f to &mut self where f takes a single parameter of type Param
and Self implements trait DerefMut<Param>. Read more
impl<T> ToOwned for T where
T: Clone, [src]
impl<T> ToOwned for T where
T: Clone, [src]type Owned = T
type Owned = TThe resulting type after obtaining ownership.
pub fn to_owned(&self) -> T[src]
pub fn to_owned(&self) -> T[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)[src]
pub fn clone_into(&self, target: &mut T)[src]🔬 This is a nightly-only experimental API. (toowned_clone_into)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more