Crates.io | yafp |
lib.rs | yafp |
version | 0.2.0 |
source | src |
created_at | 2024-07-14 20:08:13.052967 |
updated_at | 2024-08-04 16:17:50.716937 |
description | yafp is a non-POSIX cli flag parser with imperative style flag declaration instead of the usual declarative style. |
homepage | |
repository | https://github.com/joaonsantos/yafp |
max_upload_size | |
id | 1303222 |
size | 23,997 |
yafp is a non-POSIX cli flag parser with imperative style flag declaration instead of the usual declarative style.
Features:
false
by default and true
if set.Limitations:
-fd
is not -f
and -d
and is instead a single flag.use yafp::Parser;
fn main() {
let mut parser = Parser::from_env();
// Declare flags.
parser.bool_flag("verbose", "this is used to get verbose output");
parser.required_flag("url", "this is a required flag");
parser.required_flag("workers", "this is an optional flag");
// finalize() must be called before accessing arguments.
// Unbound args are returned if any.
//
// An error is returned if there is a parsing error.
let result = parser.finalize();
let remaining = match result {
Ok(remaining) => remaining,
Err(e) => {
println!("{}: {}", parser.command, e);
exit(1);
}
};
// yafp parses values to the correct type.
let verbose: bool = parser.get_value("verbose").unwrap();
//...
}
MIT