gamenight/gamenight-cli/src/flows/rename_game.rs

47 lines
1.2 KiB
Rust

use std::fmt::Display;
use async_trait::async_trait;
use gamenight_api_client_rs::{apis::default_api::rename_game_post, models::RenameGameRequestBody};
use inquire::Text;
use crate::domain::game::Game;
use super::{Flow, FlowOutcome, FlowResult, GamenightState};
#[derive(Clone)]
pub struct RenameGame {
pub game: Game
}
impl RenameGame {
pub fn new(game: Game) -> Self {
Self{
game
}
}
}
#[async_trait]
impl<'a> Flow<'a> for RenameGame {
async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> {
if let Some(name) = Text::new(&format!("Rename {} to:", self.game.name))
.with_initial_value(&format!("{}", self.game.name))
.prompt_skippable()?
{
let req = RenameGameRequestBody {
id: self.game.id.to_string(),
name
};
rename_game_post(&state.api_configuration, Some(req)).await?;
return Ok((FlowOutcome::Successful, state))
}
Ok((FlowOutcome::Cancelled, state))
}
}
impl Display for RenameGame {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Rename")
}
}