1use bpaf::*;
4use std::path::PathBuf;
5
6#[allow(dead_code)]
7#[derive(Debug, Clone)]
8struct Out {
9 debug: bool,
10 verbose: usize,
11 speed: f64,
12 output: PathBuf,
13 nb_cars: u32,
14 files_to_process: Vec<PathBuf>,
15}
16
17fn opts() -> OptionParser<Out> {
18 let debug = short('d') .long("debug") .help("Activate debug mode") .switch(); let verbose = short('v')
28 .long("verbose")
29 .help("Increase the verbosity\n You can specify it up to 3 times\n either as -v -v -v or as -vvv")
30 .req_flag(())
31 .many()
32 .map(|xs| xs.len())
33 .guard(|&x| x <= 3, "It doesn't get any more verbose than this");
34
35 let speed = short('s')
37 .long("speed")
38 .help("Set speed")
39 .argument::<f64>("SPEED") .fallback(42.0)
41 .display_fallback();
42
43 let output = short('o')
44 .long("output")
45 .help("output file")
46 .argument::<PathBuf>("OUTPUT") .complete_shell(ShellComp::File { mask: None });
48
49 let nb_cars = short('n')
51 .long("nb-cars")
52 .help("Number of items to process")
53 .argument::<u32>("N")
54 .fallback(1)
55 .display_fallback();
56
57 let file_to_proces = short('f')
61 .long("file")
62 .help("File to process")
63 .argument::<PathBuf>("FILE")
64 .complete_shell(ShellComp::File { mask: Some("*.rs") });
65
66 let files_to_process = file_to_proces.many();
67
68 construct!(Out {
70 debug,
71 verbose,
72 speed,
73 output,
74 nb_cars,
75 files_to_process
76 })
77 .to_options()
78 .descr("This is a description")
79}
80
81fn main() {
82 let opts = opts().fallback_to_usage().run();
83 println!("{:#?}", opts);
84}