compression/
compression.rs

1//! Numeric flags similar to zip compression levels, accepts -1 to -9, produces usize
2
3use bpaf::{doc::Style, *};
4
5fn compression() -> impl Parser<usize> {
6    any::<isize, _, _>("COMP", |x: isize| {
7        if (-9..=-1).contains(&x) {
8            Some(x.abs().try_into().unwrap())
9        } else {
10            None
11        }
12    })
13    .metavar(&[
14        ("-1", Style::Literal),
15        (" to ", Style::Text),
16        ("-9", Style::Literal),
17    ])
18    .help("Compression level")
19    .anywhere()
20}
21
22fn main() {
23    let opts = compression().to_options().run();
24
25    println!("{:?}", opts);
26}