Struct argparse::parser::ArgumentParser [−][src]
pub struct ArgumentParser<'parser> { /* fields omitted */ }
The main argument parser class
Methods
impl<'parser> ArgumentParser<'parser>
[src]
impl<'parser> ArgumentParser<'parser>
pub fn new() -> ArgumentParser<'parser>
[src]
pub fn new() -> ArgumentParser<'parser>
Create an empty argument parser
pub fn refer<'x, T>(
&'x mut self,
val: &'parser mut T
) -> Box<Ref<'parser, 'x, T>>
[src]
pub 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
pub fn add_option<F: IFlagAction + 'parser>(
&mut self,
names: &[&'parser str],
action: F,
help: &'parser str
)
[src]
pub fn add_option<F: IFlagAction + 'parser>(
&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(...)
pub fn set_description(&mut self, descr: &'parser str)
[src]
pub fn set_description(&mut self, descr: &'parser str)
Set description of the command
pub fn print_help(&self, name: &str, writer: &mut Write) -> IoResult<()>
[src]
pub 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
pub fn print_usage(&self, name: &str, writer: &mut Write) -> IoResult<()>
[src]
pub fn print_usage(&self, name: &str, writer: &mut Write) -> IoResult<()>
Print usage
Usually printed into stderr on error of command-line parsing
pub fn parse(
&self,
args: Vec<String>,
stdout: &mut Write,
stderr: &mut Write
) -> Result<(), i32>
[src]
pub fn parse(
&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
pub fn error(&self, command: &str, message: &str, writer: &mut Write)
[src]
pub 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
pub fn stop_on_first_argument(&mut self, want_stop: bool)
[src]
pub 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.
pub fn silence_double_dash(&mut self, silence: bool)
[src]
pub 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.
pub fn parse_args(&self) -> Result<(), i32>
[src]
pub 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)
pub fn parse_args_or_exit(&self)
[src]
pub 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.
Auto Trait Implementations
impl<'parser> !Send for ArgumentParser<'parser>
impl<'parser> !Send for ArgumentParser<'parser>
impl<'parser> !Sync for ArgumentParser<'parser>
impl<'parser> !Sync for ArgumentParser<'parser>