foropts-rs: iterator-style option parsing for Rust
Most argument parsing libraries, such as
clap
treat the arguments as a
multimap; foropts
treats the arguments as a sequence. This usually
isn’t what you want, but occasionally it is.
Usage
It's on crates.io, so you can add
= "0.1"
to your Cargo.toml
and
extern crate foropts;
to your crate root.
Example
In this example, we accept one boolean flag, -v
(or --verbose
), and two
string options, -b
(or --before
) and -a
(or --after
). The string options
build a string, where the relative order of the appearances of -a
and -b
matters.
This is hard to do when your arguments are treated as a multimap, but easy when
you can iterate over them sequentially.
use foropts;
let config =
new
.arg
.arg
.arg;
let mut verbose = false;
let mut accumulator = String new;
let opts =
.iter.map;
for opt in config.iter
assert_eq!;
assert!;