Struct docopt::Docopt[][src]

pub struct Docopt { /* fields omitted */ }

The main Docopt type, which is constructed with a Docopt usage string.

This can be used to match command line arguments to produce a ArgvMap.

Implementations

impl Docopt[src]

pub fn new<S>(usage: S) -> Result<Docopt, Error> where
    S: Deref<Target = str>, 
[src]

Parse the Docopt usage string given.

The Docopt value returned may be used immediately to parse command line arguments with a default configuration.

If there was a problem parsing the usage string, a Usage error is returned.

pub fn deserialize<'a, 'de: 'a, D>(&'a self) -> Result<D, Error> where
    D: Deserialize<'de>, 
[src]

Parse and deserialize the given argv.

This is a convenience method for parse().and_then(|vals| vals.deserialize()).

For details on how decoding works, please see the documentation for ArgvMap.

pub fn parse(&self) -> Result<ArgvMap, Error>[src]

Parse command line arguments and try to match them against a usage pattern specified in the Docopt string.

If there is a match, then an ArgvMap is returned, which maps flags, commands and arguments to values.

If parsing the command line arguments fails, then an Argv error is returned. If parsing succeeds but there is no match, then a NoMatch error is returned. Both of these errors are always returned inside a WithProgramUsage error.

If special handling of help or version is enabled (the former is enabled by default), then Help or Version errors are returned if --help or --version is present.

pub fn argv<I, S>(self, argv: I) -> Docopt where
    I: IntoIterator<Item = S>,
    S: AsRef<str>, 
[src]

Set the argv to be used for Docopt parsing.

By default, when no argv is set, and it is automatically taken from std::env::args().

The argv given must be the full set of argv passed to the program. e.g., ["cp", "src", "dest"] is right while ["src", "dest"] is wrong.

pub fn options_first(self, yes: bool) -> Docopt[src]

Enables the “options first” Docopt behavior.

The options first behavior means that all flags must appear before position arguments. That is, after the first position argument is seen, all proceeding arguments are interpreted as positional arguments unconditionally.

pub fn help(self, yes: bool) -> Docopt[src]

Enables automatic handling of --help.

When this is enabled and --help appears anywhere in the arguments, then a Help error will be returned. You may then use the exit method on the error value to conveniently quit the program (which will print the full usage string to stdout).

Note that for this to work, --help must be a valid pattern.

When disabled, there is no special handling of --help.

pub fn version(self, version: Option<String>) -> Docopt[src]

Enables automatic handling of --version.

When this is enabled and --version appears anywhere in the arguments, then a Version(s) error will be returned, where s is the string given here. You may then use the exit method on the error value to convenient quit the program (which will print the version to stdout).

When disabled (a None value), there is no special handling of --version.

Trait Implementations

impl Clone for Docopt[src]

impl Debug for Docopt[src]

Auto Trait Implementations

impl RefUnwindSafe for Docopt

impl Send for Docopt

impl Sync for Docopt

impl Unpin for Docopt

impl UnwindSafe for Docopt

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.