Crates.io | parse_argument |
lib.rs | parse_argument |
version | 0.1.5 |
source | src |
created_at | 2023-09-12 03:11:49.409341 |
updated_at | 2023-09-15 16:35:00.527313 |
description | A simple way to deal with taking in commandline arguments |
homepage | |
repository | https://github.com/connorm400/parse_arguments_rs |
max_upload_size | |
id | 970390 |
size | 9,663 |
Easy way to deal with parsing commandline arguments
Can be used with any type that implements FromStr (for parsing).
Use parse_argument()
function to find a value for a specified key (flag).
Look at the examples for an idea of how to use it.
It works for arguments that look like this:
./rust_code --setting=foo --num=42 --hello="world"
And to retrieve those values you would write:
// assuming you made a Setting enum that implemented FromStr trait
let _ = parse_argument::<Setting>("setting").unwrap().unwrap();
let _ = parse_argument::<i32>("num").unwrap().unwrap();
let _ = parse_argument::<String>("hello").unwrap().unwrap();
Alternativelly, you can convert the arguments into a hashmap:
let _ = args_to_hashmap();
// which would, in this example, look like {"num": "42", "hello": "world", "setting": "foo"}
Run cargo doc --open
or go to docs.rs to see the documentation.