Enum clap::ErrorKind
[−]
[src]
pub enum ErrorKind {
InvalidValue,
UnknownArgument,
InvalidSubcommand,
UnrecognizedSubcommand,
EmptyValue,
ValueValidation,
TooManyValues,
TooFewValues,
WrongNumberOfValues,
ArgumentConflict,
MissingRequiredArgument,
MissingSubcommand,
MissingArgumentOrSubcommand,
UnexpectedMultipleUsage,
InvalidUtf8,
HelpDisplayed,
VersionDisplayed,
ArgumentNotFound,
Io,
Format,
}Command line argument parser kind of error
Variants
InvalidValue | Occurs when an Exampleslet result = App::new("myprog") .arg(Arg::with_name("speed") .possible_value("fast") .possible_value("slow")) .get_matches_from_safe(vec!["myprog", "other"]); assert!(result.is_err()); assert_eq!(result.unwrap_err().kind, ErrorKind::InvalidValue); | |
UnknownArgument | Occurs when a user provides a flag, option, or argument which wasn't defined. Exampleslet result = App::new("myprog") .arg(Arg::from_usage("--flag 'some flag'")) .get_matches_from_safe(vec!["myprog", "--other"]); assert!(result.is_err()); assert_eq!(result.unwrap_err().kind, ErrorKind::UnknownArgument); | |
InvalidSubcommand | Occurs when the user provids an unrecognized subcommand which meets the threshold for being
similar enough to an existing subcommand so as to not cause the more general
Exampleslet result = App::new("myprog") .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!["myprog", "confi"]); assert!(result.is_err()); assert_eq!(result.unwrap_err().kind, ErrorKind::InvalidSubcommand); | |
UnrecognizedSubcommand | Occurs when the user provids an unrecognized subcommand which does not meet the threshold
for being similar enough to an existing subcommand so as to not cause the more detailed
This error typically happens when passing additional subcommand names to the Exampleslet result = App::new("myprog") .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!["myprog", "help", "nothing"]); assert!(result.is_err()); assert_eq!(result.unwrap_err().kind, ErrorKind::UnrecognizedSubcommand); | |
EmptyValue | Occurs when the user provides an empty value for an option that does not allow empty values. Exampleslet res = App::new("myprog") .arg(Arg::with_name("color") .long("color") .empty_values(false)) .get_matches_from_safe(vec!["myprog", "--color="]); assert!(res.is_err()); assert_eq!(res.unwrap_err().kind, ErrorKind::EmptyValue); | |
ValueValidation | Occurs when the user provides a value for an argument with a custom validation and the value fails that validation. Examplesfn 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("myprog") .arg(Arg::with_name("num") .validator(is_numeric)) .get_matches_from_safe(vec!["myprog", "NotANumber"]); assert!(result.is_err()); assert_eq!(result.unwrap_err().kind, ErrorKind::ValueValidation); | |
TooManyValues | Occurs when a user provides more values for an argument than were defined by setting
Exampleslet result = App::new("myprog") .arg(Arg::with_name("arg") .multiple(true) .max_values(2)) .get_matches_from_safe(vec!["myprog", "too", "many", "values"]); assert!(result.is_err()); assert_eq!(result.unwrap_err().kind, ErrorKind::TooManyValues); | |
TooFewValues | Occurs when the user provides fewer values for an argument than were defined by setting
Exampleslet result = App::new("myprog") .arg(Arg::with_name("some_opt") .long("opt") .min_values(3)) .get_matches_from_safe(vec!["myprog", "--opt", "too", "few"]); assert!(result.is_err()); assert_eq!(result.unwrap_err().kind, ErrorKind::TooFewValues); | |
WrongNumberOfValues | Occurs when the user provides a different number of values for an argument than what's
been defined by setting Exampleslet result = App::new("myprog") .arg(Arg::with_name("some_opt") .long("opt") .takes_value(true) .number_of_values(2)) .get_matches_from_safe(vec!["myprog", "--opt", "wrong"]); assert!(result.is_err()); assert_eq!(result.unwrap_err().kind, ErrorKind::WrongNumberOfValues); | |
ArgumentConflict | Occurs when the user provides two values which conflict with each other and can't be used together. Exampleslet result = App::new("myprog") .arg(Arg::with_name("debug") .long("debug") .conflicts_with("color")) .arg(Arg::with_name("color") .long("color")) .get_matches_from_safe(vec!["myprog", "--debug", "--color"]); assert!(result.is_err()); assert_eq!(result.unwrap_err().kind, ErrorKind::ArgumentConflict); | |
MissingRequiredArgument | Occurs when the user does not provide one or more required arguments. Exampleslet result = App::new("myprog") .arg(Arg::with_name("debug") .required(true)) .get_matches_from_safe(vec!["myprog"]); assert!(result.is_err()); assert_eq!(result.unwrap_err().kind, ErrorKind::MissingRequiredArgument); | |
MissingSubcommand | Occurs when a subcommand is required (as defined by Exampleslet err = App::new("myprog") .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); | |
MissingArgumentOrSubcommand | Occurs when either an argument or subcommand is required, as defined by
Exampleslet result = App::new("myprog") .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!["myprog"]); assert!(result.is_err()); assert_eq!(result.unwrap_err().kind, ErrorKind::MissingArgumentOrSubcommand); | |
UnexpectedMultipleUsage | Occurs when the user provides an argument multiple times which has not been set to allow multiple uses. Exampleslet result = App::new("myprog") .arg(Arg::with_name("debug") .long("debug") .multiple(false)) .get_matches_from_safe(vec!["myprog", "--debug", "--debug"]); assert!(result.is_err()); assert_eq!(result.unwrap_err().kind, ErrorKind::UnexpectedMultipleUsage); | |
InvalidUtf8 | Occurs when the user provides a value containing invalid UTF-8 for an argument and
Platform SpeicificNon-Windows platforms only (such as Linux, Unix, OSX, etc.) Exampleslet result = App::new("myprog") .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); | |
HelpDisplayed | Not a true "error" as it means Note: If the help is displayed due to an error (such as missing subcommands) it will
be sent to Exampleslet result = App::new("myprog") .get_matches_from_safe(vec!["myprog", "--help"]); assert!(result.is_err()); assert_eq!(result.unwrap_err().kind, ErrorKind::HelpDisplayed); | |
VersionDisplayed | Not a true "error" as it means Exampleslet result = App::new("myprog") .get_matches_from_safe(vec!["myprog", "--version"]); assert!(result.is_err()); assert_eq!(result.unwrap_err().kind, ErrorKind::VersionDisplayed); | |
ArgumentNotFound | Occurs when using the | |
Io | Represents an I/O error, typically while writing to | |
Format | Represents an Rust Display Format error, typically white writing to |