1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use clap::{crate_authors, crate_name, crate_version, value_parser, ArgAction, Parser, Subcommand};
use fluent_templates::Loader;

use crate::{
    cmd::{
        build::Build, check::Check, completions::Completions, download::Download,
        favorites::Favorites, info::Info, real_cugan::RealCugan, search::Search,
        transform::Transform, unzip::Unzip, update::Update, zip::Zip,
    },
    LANG_ID, LOCALES,
};

#[derive(Debug, Parser)]
#[command(author, version, about = about_msg(), long_about = None, propagate_version = true)]
pub struct Config {
    #[command(subcommand)]
    pub command: Commands,

    #[arg(long, short, action = ArgAction::Count, global = true, default_value_t = 0,
        value_parser = value_parser!(u8).range(0..=5),
        help = LOCALES.lookup(&LANG_ID, "verbose").expect("`verbose` does not exists"))]
    pub verbose: u8,

    #[arg(long, short, global = true, conflicts_with = "verbose", default_value_t = false,
        help = LOCALES.lookup(&LANG_ID, "quiet").expect("`quiet` does not exists"))]
    pub quiet: bool,
}

#[derive(Debug, Subcommand)]
pub enum Commands {
    Download(Download),
    Search(Search),
    Info(Info),
    Favorites(Favorites),
    Transform(Transform),
    Check(Check),
    Build(Build),
    Zip(Zip),
    Unzip(Unzip),
    RealCugan(RealCugan),
    Update(Update),
    Completions(Completions),
}

fn about_msg() -> &'static str {
    concat!(
        crate_name!(),
        " ",
        crate_version!(),
        "\nAuthor: ",
        crate_authors!(),
        "\nProject home page: ",
        env!("CARGO_PKG_HOMEPAGE"),
    )
}

#[cfg(test)]
mod tests {
    use clap::CommandFactory;

    use super::*;

    #[test]
    fn verify_cli() {
        Config::command().debug_assert()
    }
}