[−][src]Struct arguably::ArgParser
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]
S: Into<String>,
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]
S: Into<String>,
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("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
function will be called and passed the command name and a reference to the
command's ArgParser
instance.
pub fn value(&self, name: &str) -> Result<Option<String>, Error>
[src]
Returns the value of the named option. Returns Error::InvalidName
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 Error::InvalidName
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 flag or option was found. Returns Error::InvalidName
if name
is not a registered flag or option name.
pub fn found(&self, name: &str) -> Result<bool, Error>
[src]
Returns true
if the named flag or option was found. Returns Error::InvalidName
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 strings. This function is intended for testing only.
Auto Trait Implementations
impl RefUnwindSafe for ArgParser
impl Send for ArgParser
impl Sync for ArgParser
impl Unpin for ArgParser
impl UnwindSafe for ArgParser
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,
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, 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.
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>,