[go: up one dir, main page]

Enum clap::ClapErrorType

source ·
pub enum ClapErrorType {
Show 20 variants InvalidValue, InvalidArgument, InvalidSubcommand, EmptyValue, ValueValidationError, ArgumentError, TooManyArgs, TooManyValues, TooFewValues, WrongNumValues, ArgumentConflict, MissingRequiredArgument, MissingSubcommand, MissingArgumentOrSubcommand, UnexpectedArgument, UnexpectedMultipleUsage, InvalidUnicode, HelpDisplayed, VersionDisplayed, InternalError,
}
Expand description

Command line argument parser error types

Variants§

§

InvalidValue

Error occurs when some possible values were set, but clap found unexpected value

§Examples

let result = App::new("myprog")
    .arg(Arg::with_name("debug").index(1)
        .possible_value("fast")
        .possible_value("slow"))
    .get_matches_from_safe(vec!["", "other"]);
§

InvalidArgument

Error occurs when clap found unexpected flag or option

§Examples

let result = App::new("myprog")
    .arg(Arg::from_usage("-f, --flag 'some flag'"))
    .get_matches_from_safe(vec!["", "--other"]);
§

InvalidSubcommand

Error occurs when clap found unexpected subcommand

§Examples

let result = App::new("myprog")
    .subcommand(SubCommand::with_name("conifg")
        .about("Used for configuration")
        .arg(Arg::with_name("config_file")
            .help("The configuration file to use")
            .index(1)))
    .get_matches_from_safe(vec!["", "other"]);
§

EmptyValue

Error occurs when option does not allow empty values but some was found

§Examples

let result = App::new("myprog")
    .arg(Arg::with_name("debug")
         .empty_values(false))
    .arg(Arg::with_name("color"))
    .get_matches_from_safe(vec!["", "--debug", "--color"]);
§

ValueValidationError

Option fails validation of a custom validator

§

ArgumentError

Parser inner error

§

TooManyArgs

Error occurs when an application got more arguments then were expected

§Examples

let result = App::new("myprog")
    .arg(Arg::with_name("debug").index(1)
        .max_values(2))
    .get_matches_from_safe(vec!["", "too", "much", "values"]);
§

TooManyValues

Error occurs when argument got more values then were expected

§Examples

let result = App::new("myprog")
    .arg(Arg::with_name("debug").index(1)
        .max_values(2))
    .get_matches_from_safe(vec!["", "too", "much", "values"]);
§

TooFewValues

Error occurs when argument got less values then were expected

§Examples

let result = App::new("myprog")
    .arg(Arg::with_name("debug").index(1)
        .min_values(3))
    .get_matches_from_safe(vec!["", "too", "few"]);
§

WrongNumValues

Error occurs when argument got a different number of values then were expected

§Examples

let result = App::new("myprog")
    .arg(Arg::with_name("debug").index(1)
        .max_values(2))
    .get_matches_from_safe(vec!["", "too", "much", "values"]);
§

ArgumentConflict

Error occurs when clap find two ore more conflicting arguments

§Examples

let result = App::new("myprog")
    .arg(Arg::with_name("debug")
        .conflicts_with("color"))
    .get_matches_from_safe(vec!["", "--debug", "--color"]);
§

MissingRequiredArgument

Error occurs when one or more required arguments missing

§Examples

let result = App::new("myprog")
    .arg(Arg::with_name("debug")
        .required(true))
    .get_matches_from_safe(vec![""]);
§

MissingSubcommand

Error occurs when required subcommand missing

§Examples

let result = App::new("myprog")
    .setting(AppSettings::SubcommandRequired)
    .subcommand(SubCommand::with_name("conifg")
        .about("Used for configuration")
        .arg(Arg::with_name("config_file")
            .help("The configuration file to use")
            .index(1)))
    .get_matches_from_safe(vec![""]);
§

MissingArgumentOrSubcommand

Occurs when no argument or subcommand has been supplied and AppSettings::ArgRequiredElseHelp was used

§Examples

let result = App::new("myprog")
    .setting(AppSettings::ArgRequiredElseHelp)
    .subcommand(SubCommand::with_name("conifg")
        .about("Used for configuration")
        .arg(Arg::with_name("config_file")
            .help("The configuration file to use")
            .index(1)))
    .get_matches_from_safe(vec![""]);
§

UnexpectedArgument

Error occurs when clap find argument while is was not expecting any

§Examples

let result = App::new("myprog")
    .get_matches_from_safe(vec!["", "--arg"]);
§

UnexpectedMultipleUsage

Error occurs when argument was used multiple times and was not set as multiple.

§Examples

let result = App::new("myprog")
    .arg(Arg::with_name("debug")
        .multiple(false))
    .get_matches_from_safe(vec!["", "--debug", "--debug"]);
§

InvalidUnicode

Error occurs when argument contains invalid unicode characters

§Examples

let result = App::new("myprog")
    .arg(Arg::with_name("debug")
        .short("u")
        .takes_value(true))
    .get_matches_from_safe(vec![OsString::from_vec(vec![0x20]),
                                OsString::from_vec(vec![0xE9])]);
assert!(result.is_err());
§

HelpDisplayed

Not a true ‘error’ as it means --help or similar was used. The help message will be sent to stdout unless the help is displayed due to an error (such as missing subcommands) at which point it will be sent to stderr

§Examples

let result = App::new("myprog")
    .get_matches_from_safe(vec!["", "--help"]);
assert!(result.is_err());
assert_eq!(result.unwrap_err().error_type, ClapErrorType::HelpDisplayed);
§

VersionDisplayed

Not a true ‘error’ as it means --version or similar was used. The message will be sent to stdout

§Examples

let result = App::new("myprog")
    .get_matches_from_safe(vec!["", "--version"]);
assert!(result.is_err());
assert_eq!(result.unwrap_err().error_type, ClapErrorType::VersionDisplayed);
§

InternalError

Represents an internal error, please consider filing a bug report if this happens!

Trait Implementations§

source§

impl Clone for ClapErrorType

source§

fn clone(&self) -> ClapErrorType

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ClapErrorType

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq for ClapErrorType

source§

fn eq(&self, other: &ClapErrorType) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for ClapErrorType

source§

impl StructuralPartialEq for ClapErrorType

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> CloneToUninit for T
where T: Copy,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.