argwerk
Helper utility for parsing simple commandline arguments.
This is not intended to be a complete commandline parser library.
Instead this can be used as an alternative quick-and-dirty approach that can
be cheaply incorporated into a tool.
For a more complete commandline parsing library, use clap.
Examples
This is available as a runnable example:
cargo run --example tour
let args = argwerk::parse! {
"testcommand [-h]" {
help: bool,
file: Option<String>,
limit: usize = 42,
positional: Option<(String, String)>,
rest: Vec<String>,
}
"-h" | "--help" => {
help = true;
print_help();
Ok(())
}
"--limit" | "-l", n => {
limit = str::parse(&n)?;
Ok(())
}
"--file", path if !file.is_some() => {
file = Some(path);
Ok(())
}
(foo, bar, #[rest] args) if positional.is_none() => {
positional = Some((foo.into(), bar.into()));
rest = args;
Ok(())
}
}?;
dbg!(args);
Ok(())
License: MIT/Apache-2.0