Crates.io | cli-parser |
lib.rs | cli-parser |
version | 0.1.0 |
source | src |
created_at | 2024-07-24 19:02:09.803392 |
updated_at | 2024-07-24 19:02:09.803392 |
description | Lightweight API for parsing CLI arguments |
homepage | |
repository | https://github.com/gzarpapis/cli-parser |
max_upload_size | |
id | 1314244 |
size | 6,899 |
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.
./my_program --debug_level=2 -verb path/to/file
These arguments are classified as:
./my_program
path/to/file
verb
debug_level
with value 2
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
}