[][src]Struct arguably::ArgParser

pub struct ArgParser { /* fields omitted */ }

An ArgParser instance can be intialized using the builder pattern.

let parser = ArgParser::new()
    .helptext("Usage: appname...")
    .version("1.0")
    .flag("foo f")
    .option("bar b");

Implementations

impl ArgParser[src]

pub fn new() -> ArgParser[src]

Creates a new ArgParser instance.

pub fn helptext<S>(self, text: S) -> Self where
    S: Into<String>, 
[src]

Sets the parser's helptext string. Supplying a helptext string turns on support for an automatic --help/-h flag.

let parser = ArgParser::new()
    .helptext("Usage: appname...");

pub fn version<S>(self, text: S) -> Self where
    S: Into<String>, 
[src]

Sets the parser's version string. Supplying a version string turns on support for an automatic --version/-v flag.

let parser = ArgParser::new()
    .version("1.0");

pub fn option(self, name: &str) -> Self[src]

Registers a new option. The name parameter accepts an unlimited number of space-separated aliases and single-character shortcuts.

let parser = ArgParser::new()
    .option("name1 name2 n");

pub fn flag(self, name: &str) -> Self[src]

Registers a new flag. The name parameter accepts an unlimited number of space-separated aliases and single-character shortcuts.

let parser = ArgParser::new()
    .flag("name1 name2 n");

pub fn command(self, name: &str, cmd_parser: ArgParser) -> Self[src]

Registers a new command. The name parameter accepts an unlimited number of space-separated aliases. The command's helptext, flags, and options can be registered on the command's ArgParser instance.

let mut parser = ArgParser::new()
    .helptext("Usage: appname...")
    .command("cmdname", ArgParser::new()
        .helptext("Usage: appname cmdname...")
        .flag("cmdflag")
    );

pub fn callback(self, f: fn(_: &str, _: &ArgParser)) -> Self[src]

Registers a callback function on a command parser. If the command is found the callback will be called and passed the command name and a reference to the command's parser instance.

pub fn enable_help_command(self) -> Self[src]

Turns on an automatic help command for printing subcommand helptext.

pub fn value(&self, name: &str) -> Result<Option<String>, Error>[src]

Returns the value of the named option. Returns an error if name is not a registered option name. Returns None if the option was not found.

pub fn values(&self, name: &str) -> Result<Vec<String>, Error>[src]

Returns the named option's list of values. Returns an error if name is not a registered option name.

pub fn count(&self, name: &str) -> Result<usize, Error>[src]

Returns the number of times the named option or flag was found. Returns an error if name is not a registered option name.

pub fn found(&self, name: &str) -> Result<bool, Error>[src]

Returns true if the named option or flag was found. Returns an error if name is not a registered option name.

pub fn has_args(&self) -> bool[src]

Returns true if one or more positional arguments have been found.

pub fn num_args(&self) -> usize[src]

Returns the number of positional arguments.

pub fn args(&self) -> Vec<String>[src]

Returns the positional arguments.

pub fn has_cmd(&self) -> bool[src]

Returns true if a command was found.

pub fn cmd_name(&self) -> Option<&str>[src]

If a command was found, returns the command's name.

pub fn cmd_parser(&self) -> Option<&ArgParser>[src]

If a command was found, returns a reference to the command's ArgParser instance.

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

Parse the program's command line arguments.

if let Err(err) = parser.parse() {
    err.exit();
}

pub fn parse_args(&mut self, args: Vec<&str>) -> Result<(), Error>[src]

Parse a vector of strings. This function is intended for testing only.

Auto Trait Implementations

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, 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.