[][src]Struct arguably::ArgParser

pub struct ArgParser {
    pub args: Vec<String>,
    pub cmd_name: Option<String>,
    pub cmd_parser: Option<Box<ArgParser>>,
    pub cmd_help: bool,
    // some 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");

Fields

args: Vec<String>

Stores positional arguments.

cmd_name: Option<String>

Stores the command name, if a command was found.

cmd_parser: Option<Box<ArgParser>>

Stores the command's ArgParser instance, if a command was found.

cmd_help: bool

Boolean switch; activates support for an automatic help command which prints subcommand helptext. Defaults to false but gets toggled to true when a command with helptext is registered.

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 activates support for an automatic --help flag, also a -h shortcut if not registered by another option.

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 activates support for an automatic --version flag, also a -v shortcut if not registered by another option.

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("foo f");

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("foo f");

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 function will be called and passed the command name and a reference to the command's ArgParser instance.

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

Returns the value of the named option or None if the option was not found. (This function will panic if name is not a registered option name.)

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

Returns the named option's list of values. (This function will panic if name is not a registered option name.)

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

Returns the number of times the named flag or option was found. (This function will panic if name is not a registered flag or option name.)

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

Returns true if the named flag or option was found. (This function will panic if name is not a registered flag or option name.)

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 argument strings.

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.