mahjong_cli/
cli.rs

1use crate::{
2    base::{App, AppCommand},
3    print_game::{get_print_game_command, get_print_game_opts},
4    simulate::{get_simulate_command, get_simulate_opts},
5};
6use clap::command;
7
8pub async fn parse_args(app: &mut App) {
9    let simulate_command = get_simulate_command();
10    let print_game_command = get_print_game_command();
11
12    let matches = command!()
13        .subcommand(simulate_command)
14        .subcommand(print_game_command)
15        .get_matches();
16
17    match matches.subcommand() {
18        Some(("simulate", args_matches)) => {
19            let opts = get_simulate_opts(args_matches);
20            app.command = Some(AppCommand::Simulate(opts));
21        }
22        Some(("print-game", args_matches)) => {
23            let opts = get_print_game_opts(args_matches);
24            app.command = Some(AppCommand::PrintGame(opts));
25        }
26        _ => {
27            println!("Error: no command specified");
28            std::process::exit(1);
29        }
30    }
31}