Crates.io | optparse |
lib.rs | optparse |
version | 0.1.5 |
source | src |
created_at | 2021-04-13 10:12:15.612001 |
updated_at | 2021-04-14 09:44:54.735119 |
description | Simplified parsing of std::env and input arguments from the commandline |
homepage | |
repository | https://github.com/rootlou/optparse |
max_upload_size | |
id | 382810 |
size | 971,677 |
This project is licensed under GPLv3.
Add optparse to your Project by downloading it from crates.io or simply adding it to your dependencies:
[dependencies]
optparse = ["0.1.0"]
The documentation can be found here.
// import the crate
use optparse;
// functions/closures must take String as their only parameter
// and not return anything
fn hello(arg: String) {
println!("Hello {} \\o/", arg);
}
fn main() {
// create a new parser with a parser description
let mut parser = optparse::Parser::new("Example Description");
// register a flag and a corresponding function to be called
// from the command line
// register!(flag, command description, function/closure, parser);
optparse::register!("-welcome", "Example Description", hello, parser);
// run the parser using the arguments from std::env
// parse!(arguments, arguments length, parser)
let args: Vec<String> = std::env::args().collect();
optparse::parse!(args.clone(), args.len() as u8, parser);
}
You want to contribute? Feel free to leave a comment or create a pull request.