From 28b21dbb40a9c37bae5b540a0fde772b2762fc56 Mon Sep 17 00:00:00 2001 From: Michael Cuffaro Date: Mon, 7 Oct 2024 09:02:18 -0400 Subject: [PATCH] add undo redo to cli --- src/main.rs | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 15b0565..b408aa7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -122,24 +122,30 @@ enum Commands { value: Option, }, - /// Add tables and rows to a given database + /// Add tables, rows, and messages to a given database Add { #[command(subcommand)] add_subcommand: AddSubcommands, }, - /// Update rows and values in the database + /// Update rows, messages, and values in the database Update { #[command(subcommand)] update_subcommand: UpdateSubcommands, }, - /// Delete rows from the database + /// Delete rows and messages from the database Delete { #[command(subcommand)] delete_subcommand: DeleteSubcommands, }, + /// Undo the last row change + Undo {}, + + /// Redo the last row change + Redo {}, + /// Print the Valve configuration as a JSON-formatted string. DumpConfig {}, @@ -588,6 +594,22 @@ async fn main() -> Result<()> { } }; } + Commands::Undo {} | Commands::Redo {} => { + let valve = build_valve(&cli.source, &cli.database).expect(BUILD_ERROR); + let updated_row = match &cli.command { + Commands::Undo {} => valve.undo().await?, + Commands::Redo {} => valve.redo().await?, + _ => unreachable!(), + }; + if let Some(valve_row) = updated_row { + print!( + "{}", + json!(valve_row + .to_rich_json() + .expect("Error converting row to rich JSON")) + ); + } + } Commands::DropAll {} => { let valve = build_valve(&cli.source, &cli.database).expect(BUILD_ERROR); valve