Struct argparse::parser::ArgumentParser
[−]
[src]
pub struct ArgumentParser<'parser> { /* fields omitted */ }
The main argument parser class
Methods
impl<'parser> ArgumentParser<'parser>
[src]
fn new() -> ArgumentParser<'parser>
Create an empty argument parser
fn refer<'x, T>(&'x mut self, val: &'parser mut T) -> Box<Ref<'parser, 'x, T>>
Borrow mutable variable for an argument
This returns Ref
object which should be used configure the option
fn add_option<F: IFlagAction + 'parser>(
&mut self,
names: &[&'parser str],
action: F,
help: &'parser str
)
&mut self,
names: &[&'parser str],
action: F,
help: &'parser str
)
Add option to argument parser
This is only useful for options that don't store value. For
example Print(...)
fn set_description(&mut self, descr: &'parser str)
Set description of the command
fn print_help(&self, name: &str, writer: &mut Write) -> IoResult<()>
Print help
Usually command-line option is used for printing help, this is here for any awkward cases
fn print_usage(&self, name: &str, writer: &mut Write) -> IoResult<()>
Print usage
Usually printed into stderr on error of command-line parsing
fn parse(
&self,
args: Vec<String>,
stdout: &mut Write,
stderr: &mut Write
) -> Result<(), i32>
&self,
args: Vec<String>,
stdout: &mut Write,
stderr: &mut Write
) -> Result<(), i32>
Parse arguments
This is most powerful method. Usually you need parse_args
or parse_args_or_exit
instead
fn error(&self, command: &str, message: &str, writer: &mut Write)
Write an error similar to one produced by the library itself
Only needed if you like to do some argument validation that is out of scope of the argparse
fn stop_on_first_argument(&mut self, want_stop: bool)
Configure parser to ignore options when first non-option argument is encountered.
Useful for commands that want to pass following options to the subcommand or subprocess, but need some options to be set before command is specified.
fn silence_double_dash(&mut self, silence: bool)
Do not put double-dash (bare --
) into argument
The double-dash is used to stop parsing options and treat all the following tokens as the arguments regardless of whether they start with dash (minus) or not.
The method only useful for List
arguments. On by default. The method
allows to set option to false
so that cmd xx -- yy
will get
xx -- yy
as arguments instead of xx yy
by default. This is
useful if your --
argument is meaningful. Only first double-dash
is ignored by default.
fn parse_args(&self) -> Result<(), i32>
Convenience method to parse arguments
On error returns error code that is supposed to be returned by
an application. (i.e. zero on --help
and 2
on argument error)
fn parse_args_or_exit(&self)
The simplest conveninece method
The method returns only in case of successful parsing or exits with
appropriate code (including successful on --help
) otherwise.