summaryrefslogtreecommitdiff
path: root/src/cli.rs
blob: 0c584617cb156ba255ae154a4a4c8fe3c13bf8c7 (plain)
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
use clap::{
    arg, crate_authors, crate_description, crate_name, crate_version, Arg, ArgAction, Command,
};

pub fn cli() -> Command {
    Command::new(crate_name!())
        .about(crate_description!())
        .author(crate_authors!())
        .version(crate_version!())
        .subcommand_required(true)
        .arg_required_else_help(true)
        .allow_external_subcommands(true)
        .subcommand(
            Command::new("random")
                .about("Generates a random something")
                .args_conflicts_with_subcommands(true)
                .subcommand(
                    Command::new("henchman")
                        .about("Generates a random henchman")
                        .arg(
                            Arg::new("csv")
                                .long("csv")
                                .action(ArgAction::SetTrue)
                                .help("Output in CSV format"),
                        ),
                )
                .subcommand(Command::new("magic").about("Generates a magic item"))
                .subcommand(
                    Command::new("npc")
                        .about("Generates a random NPC with a class and magic item loadout")
                        .arg(
                            Arg::new("class")
                                .short('c')
                                .long("class")
                                .help("The class of the NPC, e.g. fighter"),
                        )
                        .arg(
                            Arg::new("level")
                                .short('l')
                                .long("level")
                                .help("The level of the NPC, e.g 18")
                                .default_value("1")
                                .value_parser(clap::value_parser!(i32)),
                        ),
                ),
        )
        .subcommand(
            Command::new("roll")
                .about("Rolls dice based on a given formula")
                .arg(arg!(<FORMULA> "The dice rolling formula"))
                .arg_required_else_help(true),
        )
        .subcommand(
            Command::new("table")
                .about("Rolls on a random table")
                .arg(arg!(<TABLE> "The name of the table to roll on"))
                .arg_required_else_help(true),
        )
}