1use bpaf::{short, Bpaf, Parser};
4use std::path::PathBuf;
5
6#[derive(Debug, Clone, Bpaf)]
7#[bpaf(options, version)]
8#[allow(dead_code)]
9struct Opts {
10 #[bpaf(short, long)]
12 debug: bool,
13 #[bpaf(external(verbose))]
15 verbose: usize,
16 #[bpaf(argument("SPEED"), fallback(42.0))]
18 speed: f64,
19 output: PathBuf,
21
22 #[bpaf(guard(positive, "must be positive"), fallback(1))]
23 nb_cars: u32,
24 files_to_process: Vec<PathBuf>,
25}
26
27fn verbose() -> impl Parser<usize> {
28 short('v')
30 .long("verbose")
31 .help("Increase the verbosity\nYou can specify it up to 3 times\neither as -v -v -v or as -vvv")
32 .req_flag(())
33 .many()
34 .map(|xs| xs.len())
35 .guard(|&x| x <= 3, "It doesn't get any more verbose than this")
36}
37
38fn positive(input: &u32) -> bool {
39 *input > 0
40}
41
42fn main() {
43 println!("{:#?}", opts().run());
44}