mahjong_cli/simulate/
simulate_cli.rs

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
use clap::{Arg, ArgAction, Command};

#[derive(Debug, Clone, PartialEq)]
pub struct SimulateOpts {
    pub once: bool,
    pub debug: bool,
}

pub fn get_simulate_command() -> Command {
    Command::new("simulate")
        .about("Simulates games")
        .arg(
            Arg::new("once")
                .short('o')
                .help("Only run one simulation")
                .action(ArgAction::SetTrue),
        )
        .arg(
            Arg::new("debug")
                .short('d')
                .help("Store debugging information to troubleshoot issues")
                .action(ArgAction::SetTrue),
        )
}

pub fn get_simulate_opts(matches: &clap::ArgMatches) -> SimulateOpts {
    let once: Option<&bool> = matches.get_one("once");
    let debug: Option<&bool> = matches.get_one("debug");

    SimulateOpts {
        once: once == Some(&true),
        debug: debug == Some(&true),
    }
}