Skip to content

Commit

Permalink
add undo redo to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
lmcmicu committed Oct 7, 2024
1 parent 49b70cc commit 28b21db
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,24 +122,30 @@ enum Commands {
value: Option<String>,
},

/// 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 {},

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 28b21db

Please sign in to comment.