area/
main.rs

1use {
2    clap::{CommandFactory, Parser, ValueEnum},
3    clap_help::Printer,
4};
5
6static INTRO: &str = "
7Compute `height x width`
8*You can do it either precisely (enough) or fast (I mean not too slow)*.
9";
10
11/// Application launch arguments
12#[derive(Parser, Debug)]
13#[command(name = "area", author, version, about, disable_help_flag = true)]
14struct Args {
15    /// Print help
16    #[arg(long)]
17    help: bool,
18
19    /// Height, that is the distance between bottom and top
20    #[arg(short, long, default_value = "9")]
21    height: u16,
22
23    /// Width, from there, to there, eg `4` or `5`
24    #[arg(short, long, default_value = "3")]
25    width: u16,
26
27    /// Kill all birds to improve computation
28    #[arg(short, long)]
29    kill_birds: bool,
30
31    /// Computation strategy
32    #[arg(long, default_value = "fast")]
33    strategy: Strategy,
34
35    /// Bird separator
36    #[arg(short, long, value_name = "SEP")]
37    separator: Option<String>,
38
39    /// Root Directory
40    pub root: Option<std::path::PathBuf>,
41}
42
43#[derive(ValueEnum, Clone, Copy, Debug)]
44enum Strategy {
45    Fast,
46    Precise,
47}
48
49fn main() {
50    let args = Args::parse();
51
52    if args.help {
53        Printer::new(Args::command())
54            .with("introduction", INTRO)
55            .without("author")
56            .print_help();
57        return;
58    }
59
60    let (w, h) = (args.width, args.height);
61    println!("Computation strategy: {:?}", args.strategy);
62    println!("{w} x {h} = {}", w * h);
63}