Enum docopt::Error [−][src]
pub enum Error { Usage(String), Argv(String), NoMatch, Deserialize(String), WithProgramUsage(Box<Error>, String), Help, Version(String), }
Expand description
Represents the different types of Docopt errors.
This error type has a lot of variants. In the common case, you probably
don’t care why Docopt has failed, and would rather just quit the program
and show an error message instead. The exit
method defined on the Error
type will do just that. It will also set the exit code appropriately
(no error for --help
or --version
, but an error code for bad usage,
bad argv, no match or bad decode).
Example
Generally, you want to parse the usage string, try to match the argv and then quit the program if there was an error reported at any point in that process. This can be achieved like so:
use docopt::Docopt; const USAGE: &'static str = " Usage: ... "; let args = Docopt::new(USAGE) .and_then(|d| d.parse()) .unwrap_or_else(|e| e.exit());
Variants
Parsing the usage string failed.
This error can only be triggered by the programmer, i.e., the writer of the Docopt usage string. This error is usually indicative of a bug in your program.
Tuple Fields of Usage
0: String
Parsing the argv specified failed.
The payload is a string describing why the arguments provided could not be parsed.
This is distinct from NoMatch
because it will catch errors like
using flags that aren’t defined in the usage string.
Tuple Fields of Argv
0: String
The given argv parsed successfully, but it did not match any example usage of the program.
Regrettably, there is no descriptive message describing why the given argv didn’t match any of the usage strings.
This indicates a problem deserializing a successful argv match into a deserializable value.
Tuple Fields of Deserialize
0: String
Parsing failed, and the program usage should be printed next to the
failure message. Typically this wraps Argv
and NoMatch
errors.
Decoding or parsing failed because the command line specified that the help message should be printed.
Decoding or parsing failed because the command line specified that the version should be printed
The version is included as a payload to this variant.
Tuple Fields of Version
0: String
Implementations
Return whether this was a fatal error or not.
Non-fatal errors include requests to print the help or version information of a program, while fatal errors include those such as failing to decode or parse.
Trait Implementations
Raised when there is general error when deserializing a type. Read more
Raised when a Deserialize
receives a type different from what it was
expecting. Read more
Raised when a Deserialize
receives a value of the right type but that
is wrong for some other reason. Read more
Raised when deserializing a sequence or map and the input data contains too many or too few elements. Read more
Raised when a Deserialize
enum type received a variant with an
unrecognized name. Read more
Raised when a Deserialize
struct type received a field with an
unrecognized name. Read more
Raised when a Deserialize
struct type expected to receive a required
field with a particular name but that field was not present in the
input. Read more
Raised when a Deserialize
struct type received more than one of the
same field. Read more