pub struct CLIParser {
pub posits: Vec<String>,
pub flags: HashSet<String>,
pub pairs: HashMap<String, String>,
}
Fields§
§posits: Vec<String>
Positional arguments.
These are the standard arguments without any special syntax.
Example:
./my_program posit_argument_1 posit_argument_2
flags: HashSet<String>
Flags.
These arguments are prefixed with a singular dash line. They are unique, unordered and don’t take any values.
Example:
./my_program -test_mode -verbose
pairs: HashMap<String, String>
Key - value pairs.
These arguments are prefixed with a double dash line. They need to be connected to their value with an equal sign.
Example
./my_program --debug_level=2 --id=5 --name="John Smith"
Implementations§
Source§impl CLIParser
impl CLIParser
Sourcepub fn init(self) -> Result<Self, CLIError>
pub fn init(self) -> Result<Self, CLIError>
Parses the std::env::args()
and collects them into data structures.
Will throw error if CLI arguments are considered malformed by this crate.
// Initialize parser
let parser = cliparser::CLIParser::new().init().unwrap();
// Extract parsed data structures
let posit_arguments = parser.posits.clone(); // Vector
let flags = parser.flags.clone(); // HashSet
let pairs = parser.pairs.clone(); // HashMap
Trait Implementations§
impl Eq for CLIParser
impl StructuralPartialEq for CLIParser
Auto Trait Implementations§
impl Freeze for CLIParser
impl RefUnwindSafe for CLIParser
impl Send for CLIParser
impl Sync for CLIParser
impl Unpin for CLIParser
impl UnwindSafe for CLIParser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more