Expand description
§Argument Syntax
This crate provides a complete implementation of the argument parsing algorithm described in
https://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html
Arguments are converted into basics, flags, pairs, and a few other types according to the GNU-style.
Here is a visual example of how a sequence of arguments is converted with "xy"
specified as short pairs:
$ program arg1 -abcx12 -y 3 --long --key=value - arg2 -- -kh --ignore
| | |||| | | | | | | | |
Basic(program)|||| | | | | | | Basic(-kh)
Basic(arg1) | | | | | | Basic(--ignore)
Flag(a) | | | | | |
Flag(b)| | | | | |
Flag(c) | | | | |
Pair(x,12) | | | | |
Pair(y,3) | | | |
Flag(long) | | |
Pair(key,value) |
Stdin |
Basic(arg2)
Done
The easiest way to use this crate is with ArgsExt::opts
and Opt::simplify
.
The extension trait is implemented for every Iterator
which returns String
.
This includes std::env::Args
.
For example:
use argsyn::ArgsExt;
fn main() {
for opt in std::env::args().opts("xy").unwrap() {
println!("{:?}", opt.simplify());
}
}
Structs§
- Store an alpha numeric byte which can be used as a short option
- An error returned by
Parser::new
when a non-alphanumeric short pair is given. - Flexible parser which converts arguments into
Opt
s
Enums§
- All possible options/non-options which can be parsed from arguments
- Alternative labeling of
Opt
which is easier to use inmatch
statements.