Struct docopt::ArgvMap [−][src]
A map containing matched values from command line arguments.
The keys are just as specified in Docopt: --flag
for a long flag or
-f
for a short flag. (If -f
is a synonym for --flag
, then either
key will work.) ARG
or <arg>
specify a positional argument and cmd
specifies a command.
Implementations
impl ArgvMap
[src]
pub fn deserialize<'de, T: Deserialize<'de>>(self) -> Result<T, Error>
[src]
Tries to deserialize the map of values into a struct.
This method should always be called to deserialize a ArgvMap
into
a struct. All fields of the struct must map to a corresponding key
in the ArgvMap
. To this end, each member must have a special prefix
corresponding to the different kinds of patterns in Docopt. There are
three prefixes: flag_
, arg_
and cmd_
which respectively
correspond to short/long flags, positional arguments and commands.
If a Docopt item has a -
in its name, then it is converted to an _
.
Example
use serde::Deserialize; use docopt::Docopt; const USAGE: &'static str = " Usage: cargo [options] (build | test) cargo --help Options: -v, --verbose -h, --help "; #[derive(Deserialize)] struct Args { cmd_build: bool, cmd_test: bool, flag_verbose: bool, flag_h: bool, } let argv = || vec!["cargo", "build", "-v"].into_iter(); let args: Args = Docopt::new(USAGE) .and_then(|d| d.argv(argv()).deserialize()) .unwrap_or_else(|e| e.exit()); assert!(args.cmd_build && !args.cmd_test && args.flag_verbose && !args.flag_h);
Note that in the above example, flag_h
is used but flag_help
could also be used. (In fact, both could be used at the same time.)
In this example, only the bool
type was used, but any type satisfying
the Deserialize
trait is valid.
pub fn get_bool(&self, key: &str) -> bool
[src]
Finds the value corresponding to key
and calls as_bool()
on it.
If the key does not exist, false
is returned.
pub fn get_count(&self, key: &str) -> u64
[src]
Finds the value corresponding to key
and calls as_count()
on it.
If the key does not exist, 0
is returned.
pub fn get_str(&self, key: &str) -> &str
[src]
Finds the value corresponding to key
and calls as_str()
on it.
If the key does not exist, ""
is returned.
pub fn get_vec(&self, key: &str) -> Vec<&str>
[src]
Finds the value corresponding to key
and calls as_vec()
on it.
If the key does not exist, vec!()
is returned.
pub fn find(&self, key: &str) -> Option<&Value>
[src]
Return the raw value corresponding to some key
.
key
should be a string in the traditional Docopt format. e.g.,
<arg>
or --flag
.
pub fn len(&self) -> usize
[src]
Return the number of values, not including synonyms.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for ArgvMap
impl Send for ArgvMap
impl Sync for ArgvMap
impl Unpin for ArgvMap
impl UnwindSafe for ArgvMap
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,