Struct args::Args
[−]
[src]
pub struct Args { // some fields omitted }
A dead simple implementation of command line argument parsing and validation.
Methods
impl Args
[src]
fn new(program_name: &str, description: &str) -> Args
Creates an empty set of command line options.
fn flag(&mut self, short_name: &str, long_name: &str, desc: &str) -> &mut Args
Registers an optional flag argument that does not take an argument and defaults to false.
short_name
- e.g."h"
for a-h
option, or""
for nonelong_name
- e.g."help"
for a--help
option, or""
for nonedesc
- A description of the flag for the usage message
fn full_usage(&self) -> String
Generates a combination of the short and verbose usage messages.
fn has_options(&self) -> bool
Returns a bool
indicating whether or not any options are registered.
fn has_value(&self, opt_name: &str) -> bool
Returns a bool
indicating whether or not a argument is present.
fn iter(&self) -> Iter<String, String>
Returns an iterator visiting all key-value pairs in alphabetical order.
fn option(&mut self, short_name: &str, long_name: &str, desc: &str, hint: &str, occur: Occur, default: Option<String>) -> &mut Args
Registers an option explicitly.
short_name
- e.g."h"
for a-h
option, or""
for nonelong_name
- e.g."help"
for a--help
option, or""
for nonedesc
- A description of the flag for the usage messagehint
- A hint to be used in place of the argument in the usage message, e.g."FILE"
for a-o FILE
optionoccur
- An enum representing whether the option is required or notdefault
- The default value for this option if there should be one
fn parse<C: IntoIterator>(&mut self, raw_args: C) -> Result<(), ArgsError> where C::Item: AsRef<OsStr>
Parses arguments according to the registered options.
Failures
Fails if any errors are encountered during parsing.
fn parse_from_cli(&mut self) -> Result<(), ArgsError>
Parses arguments directly from the command line according to the registered options.
Failures
Fails if any errors are encountered during parsing.
fn short_usage(&self) -> String
Generates a one-line usage summary from the registered options.
fn usage(&self) -> String
Generates a verbose usage summary from the registered options.
fn validated_value_of<T: FromStr>(&self, opt_name: &str, validations: &[Box<Validation<T=T>>]) -> Result<T, ArgsError>
Retrieves the value of the Opt
identified by opt_name
, casts it to
the type specified by T
and then runs all provided Validation
s.
Failures
Returns Err(ArgsError)
if no Opt
correspond to opt_name
, if the value cannot
be cast to type T
or if any validation is considered invalid.
fn value_of<T: FromStr>(&self, opt_name: &str) -> Result<T, ArgsError>
Retrieves the value for the Opt
identified by opt_name
and casts it to
the type specified by T
.
Failures
Returns Err(ArgsError)
if no Opt
corresponds to opt_name
or if the
value cannot be cast to type T
.
fn values_of<T: FromStr>(&self, opt_name: &str) -> Result<Vec<T>, ArgsError>
Retrieves a vector of values for the Opt
identified by opt_name
and
casts each of them to the type specified by T
.
Failures
Returns Err(ArgsError)
if no Opt
corresponds to opt_name
or if any
of the values cannot be cast to type T
.