mahjong_cli/
print_game.rs

1use std::io::Error;
2
3use clap::{Arg, Command};
4use mahjong_service::db_storage::DBStorage;
5
6#[derive(Debug, Clone, PartialEq)]
7pub struct PrintGameOpts {
8    pub game_id: String,
9}
10
11pub async fn print_game(opts: PrintGameOpts) -> Result<(), Error> {
12    let storage = DBStorage::new_dyn();
13
14    let game = storage
15        .get_game(&opts.game_id, false)
16        .await
17        .unwrap()
18        .ok_or_else(|| Error::other(format!("Game with ID {} not found", opts.game_id)))?;
19
20    println!("Game:\n{}", game.game.get_summary_sorted());
21
22    Ok(())
23}
24
25pub fn get_print_game_command() -> Command {
26    Command::new("print-game")
27        .about("Print the game summary")
28        .arg(
29            Arg::new("game-id")
30                .short('i')
31                .help("The ID of the game to print"),
32        )
33}
34
35pub fn get_print_game_opts(matches: &clap::ArgMatches) -> PrintGameOpts {
36    let game_id: &String = matches.get_one("game-id").unwrap();
37
38    PrintGameOpts {
39        game_id: game_id.clone(),
40    }
41}