custom/
main.rs

1use {
2    clap::{CommandFactory, Parser, ValueEnum},
3    clap_help::Printer,
4    termimad::ansi,
5};
6
7static INTRO: &str = "
8
9Compute `height x width`
10More info at *https://dystroy.org*
11";
12
13/// Application launch arguments
14#[derive(Parser, Debug)]
15#[command(name = "custom", author, version, about, disable_help_flag = true)]
16struct Args {
17    /// Print help
18    #[arg(long)]
19    help: bool,
20
21    /// Height, that is the distance between bottom and top
22    #[arg(short, long, default_value = "9")]
23    height: u16,
24
25    /// Width, from there, to there, eg `4` or `5`
26    #[arg(short, long, default_value = "3")]
27    width: u16,
28
29    /// Kill all birds to improve computation
30    #[arg(short, long)]
31    kill_birds: bool,
32
33    /// Computation strategy
34    #[arg(long, default_value = "fast")]
35    strategy: Strategy,
36
37    /// Bird separator
38    #[arg(short, long, value_name = "SEP")]
39    separator: Option<String>,
40
41    /// Root Directory
42    pub root: Option<std::path::PathBuf>,
43}
44
45#[derive(ValueEnum, Clone, Copy, Debug)]
46enum Strategy {
47    Fast,
48    Precise,
49}
50
51fn main() {
52    let args = Args::parse();
53
54    if args.help {
55        let mut printer = Printer::new(Args::command())
56            .without("author")
57            .with("introduction", INTRO)
58            .with("options", clap_help::TEMPLATE_OPTIONS_MERGED_VALUE);
59        let skin = printer.skin_mut();
60        skin.headers[0].compound_style.set_fg(ansi(202));
61        skin.bold.set_fg(ansi(202));
62        skin.italic = termimad::CompoundStyle::with_fg(ansi(45));
63        skin.inline_code = termimad::CompoundStyle::with_fg(ansi(223));
64        skin.table_border_chars = termimad::ROUNDED_TABLE_BORDER_CHARS;
65        printer.print_help();
66        return;
67    }
68
69    let (w, h) = (args.width, args.height);
70    println!("Computation strategy: {:?}", args.strategy);
71    println!("{w} x {h} = {}", w * h);
72}