1 unstable release
0.1.0 | Jul 24, 2024 |
---|
#783 in Command-line interface
7KB
90 lines
cli-parser
Introduction
This library provides a very light-weight API, for a singular purpose: Collect the command line arguments in 3 std
structures based on the number of dashes prefixed.
- Vector $\leftarrow$ 0 dashes $\leftarrow$ Positional arguments (values only).
- HashSet $\leftarrow$ 1 dash $\leftarrow$ Flags (keys only).
- HashMap $\leftarrow$ 2 dashes $\leftarrow$ Key - value pairs.
Syntax example:
./my_program --debug_level=2 -verb path/to/file
These arguments are classified as:
- Positional:
./my_program
path/to/file
- Flags:
verb
- Pairs:
debug_level
with value2
Usage
Just initialize the CLIParser struct and you are good to go.
use cliparser::CLIParser;
fn main() {
// Initialize parser
let parser = 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
}