pub struct ArgParser {
pub name: String,
pub author: String,
pub version: String,
pub copyright: String,
pub info: String,
pub usage: String,
pub require_args: bool,
pub extra: Vec<String>,
/* private fields */
}
Expand description
The main class for parsing
Fields
name: String
The name of the program
The author of the program
version: String
The version of the program
copyright: String
Copyright string
info: String
Simple description of the program
usage: String
Example usage of the program
require_args: bool
Whether the program has to have arguments passed or not
extra: Vec<String>
Any extra arguments that were passed, but not parsed
Implementations
sourceimpl ArgParser
impl ArgParser
sourcepub fn from_argv0() -> Self
pub fn from_argv0() -> Self
Creates a new ArgParser using the first argument (the program) as the name. Creates help and version args by default
sourcepub fn new(name: &str) -> Self
pub fn new(name: &str) -> Self
Creates a new ArgParser, with
Sets the author
sourcepub fn usage(&mut self, s: &str) -> &mut Self
pub fn usage(&mut self, s: &str) -> &mut Self
Sets the usage. Replaces all instances of {name} with the program’s name.
sourcepub fn require_args(&mut self, b: bool) -> &mut Self
pub fn require_args(&mut self, b: bool) -> &mut Self
Sets whether the program needs arguments or not
sourcepub fn args(&mut self, args: Vec<&mut Arg>) -> &mut Self
pub fn args(&mut self, args: Vec<&mut Arg>) -> &mut Self
Adds the Vec<&mut Arg> to the parser’s args
sourcepub fn map_argval(&self) -> HashMap<String, ArgVal>
pub fn map_argval(&self) -> HashMap<String, ArgVal>
Returns a copy of the parser’s current arguments in HashMap form using the ArgVal struct
sourcepub fn map_tuple(&self) -> HashMap<String, (bool, String)>
pub fn map_tuple(&self) -> HashMap<String, (bool, String)>
Returns a copy of the parser’s current arguments in HashMap form using tuples
sourcepub fn get_str(&self, name: &str) -> String
pub fn get_str(&self, name: &str) -> String
Gets a String value arg by
sourcepub fn get_bool(&self, name: &str) -> bool
pub fn get_bool(&self, name: &str) -> bool
Gets a bool value arg by
sourcepub fn version_exit(&self)
pub fn version_exit(&self)
Prints the version and exits
sourcepub fn error_exit(message: &str)
pub fn error_exit(message: &str)
Prints error
Trait Implementations
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more