parse_argument

Crates.ioparse_argument
lib.rsparse_argument
version0.1.5
sourcesrc
created_at2023-09-12 03:11:49.409341
updated_at2023-09-15 16:35:00.527313
descriptionA simple way to deal with taking in commandline arguments
homepage
repositoryhttps://github.com/connorm400/parse_arguments_rs
max_upload_size
id970390
size9,663
(connorm400)

documentation

README

parse_arguments_rs

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.

crates.io link | Github repo

Commit count: 26

cargo fmt