mahjong_cli/
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
use crate::{
    base::{App, AppCommand},
    print_game::{get_print_game_command, get_print_game_opts},
    simulate::{get_simulate_command, get_simulate_opts},
};
use clap::command;

pub async fn parse_args(app: &mut App) {
    let simulate_command = get_simulate_command();
    let print_game_command = get_print_game_command();

    let matches = command!()
        .subcommand(simulate_command)
        .subcommand(print_game_command)
        .get_matches();

    match matches.subcommand() {
        Some(("simulate", args_matches)) => {
            let opts = get_simulate_opts(args_matches);
            app.command = Some(AppCommand::Simulate(opts));
        }
        Some(("print-game", args_matches)) => {
            let opts = get_print_game_opts(args_matches);
            app.command = Some(AppCommand::PrintGame(opts));
        }
        _ => {
            println!("Error: no command specified");
            std::process::exit(1);
        }
    }
}