| Crates.io | cmdparsing |
| lib.rs | cmdparsing |
| version | 1.1.0 |
| created_at | 2025-02-21 04:25:21.572306+00 |
| updated_at | 2025-07-27 02:46:56.191933+00 |
| description | adds a macro to parse arguments |
| homepage | |
| repository | https://github.com/chickencuber/clilib |
| max_upload_size | |
| id | 1563528 |
| size | 12,264 |
a macro to do command line argument parsing
use std::env::args;
use cmdparsing::define;
define! {
Data; //name of the struct
help: "usage: cmd [file(2)] [other]"; //the usage of the command(shows when using -help, or --help(reserved flag))
flags {
t: bool = "w"|"h", // a flag that uses a boolean
f: String = "f", // a flag of type string
o: String = "l" => [2], //a flag of type string with 2 entries
};
args {
file: String => [2], //a positional argument with 2 entries(String)
other: String, //a positional arument with one entry(String)
};
rest => more: String; //a rest argument that takes strings(takes the last arguments unless its broken by a flag)
}
fn main() {
let d = Data::from(args().skip(1).collect());
println!("{:?}", d);
}
that example would generate this struct
struct Data {
t: bool,
f: Option<String>,
o: Vec<String>,
file: Vec<String>,
other: String,
more: Vec<String>,
}