[−][src]Struct arg_parser::ArgParser
Our homebrewed Arg Parser
Fields
args: Vec<String>
Methods
impl ArgParser
[src]
pub fn new(capacity: usize) -> Self
[src]
Create a new ArgParser object
The capacity specifies the initial capacity of the number parameters. Always good to set it at the number of flags and opts total. (Used for initial hashmap allocation size)
pub fn add_flag(self, flags: &[&str]) -> Self
[src]
Builder method for adding both short and long flags
Flags are just parameters that have no assigned values. They are used for when certain features or options have been enabled for the application
Examples
> ls -l --human-readable
^ ^ ^
| | |
| | `-- A long flag to enable human readable numbers.
| `-- A short flag to enable the long format.
`-- The command to list files.
pub fn add_opt(self, short: &str, long: &str) -> Self
[src]
Builder method for adding both short and long opts
Opts are parameters that hold assigned values. They are used for when certain features or options have been enabled for the application
Examples
> ls -T 4 --color=always
^ ^ ^
| | |
| | `-- A long opt to enable the use of color with value `always`.
| `-- A short opt to set tab size to the value `4`.
`-- The command to list files.
pub fn add_opt_default(self, short: &str, long: &str, default: &str) -> Self
[src]
Add an opt with a default value. Works the same way as add_opt.
pub fn add_setting(self, setting: &str) -> Self
[src]
Builder method for adding settings
Settings are parameters that hold assigned values. They are used in some applications such as dd
Examples
> dd if=/path/file
^ ^
| |
| |
| `-- The setting set to /path/file
`-- The command to list files.
pub fn add_setting_default(self, setting: &str, default: &str) -> Self
[src]
Add a setting with a default value. Works the same way as add_setting
pub fn parse<A: Iterator<Item = String>>(&mut self, args: A)
[src]
Start parsing user inputted args for which flags and opts are used at
runtime. The rest of the args that are not associated to opts get added
to ArgParser.args
.
pub fn count<P: Hash + Eq + ?Sized>(&self, name: &P) -> usize where
Param: Borrow<P>,
[src]
Param: Borrow<P>,
Get the number of times a flag or opt has been found after parsing.
pub fn found<P: Hash + Eq + ?Sized>(&self, name: &P) -> bool where
Param: Borrow<P>,
[src]
Param: Borrow<P>,
Check if a flag or opt has been found after initialization. While the short form of the opt or flag will be recognized, the long form should be used to enhance code readability.
Examples
if parser.found("my-long-flag") { //Do things... }
pub fn flag<F: Hash + Eq + ?Sized>(&mut self, flag: &F) -> RefMut<bool> where
Param: Borrow<F>,
[src]
Param: Borrow<F>,
Modify the state of a flag. Use true
if the flag is to be enabled. Use false
to
disable its use.
pub fn opt<O: Hash + Eq + ?Sized>(&mut self, opt: &O) -> RefMut<String> where
Param: Borrow<O>,
[src]
Param: Borrow<O>,
Modify the state value of an opt. Use Some(String)
to set if the opt is to be enabled and
has been assigned a value from String
. Use None
to disable the opt's use.
pub fn get_opt<O: Hash + Eq + ?Sized>(&self, opt: &O) -> Option<String> where
Param: Borrow<O>,
[src]
Param: Borrow<O>,
Get the value of an Opt. If it has been set or defaulted, it will return a Some(String)
value otherwise it will return None.
pub fn get_setting<O: Hash + Eq + ?Sized>(&self, setting: &O) -> Option<String> where
Param: Borrow<O>,
[src]
Param: Borrow<O>,
Get the value of an Setting. If it has been set or defaulted, it will return a Some(String)
value otherwise it will return None.
pub fn found_invalid(&self) -> Result<(), String>
[src]
Trait Implementations
impl Default for ArgParser
[src]
impl Clone for ArgParser
[src]
fn clone(&self) -> ArgParser
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Debug for ArgParser
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,