From 6a4a83367eb7ddaa5f949e5adf64e1f439f20a4c Mon Sep 17 00:00:00 2001 From: h7x4 Date: Wed, 3 Dec 2025 14:21:09 +0900 Subject: [PATCH] Add `--yes` flag for drop operations --- src/client/commands/drop_db.rs | 23 +++++++++++++++++++++++ src/client/commands/drop_user.rs | 23 +++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/client/commands/drop_db.rs b/src/client/commands/drop_db.rs index d195389..968b154 100644 --- a/src/client/commands/drop_db.rs +++ b/src/client/commands/drop_db.rs @@ -1,5 +1,6 @@ use clap::Parser; use clap_complete::ArgValueCompleter; +use dialoguer::Confirm; use futures_util::SinkExt; use tokio_stream::StreamExt; @@ -24,6 +25,10 @@ pub struct DropDbArgs { /// Print the information as JSON #[arg(short, long)] json: bool, + + /// Automatically confirm action without prompting + #[arg(short, long)] + yes: bool, } pub async fn drop_databases( @@ -34,6 +39,24 @@ pub async fn drop_databases( anyhow::bail!("No database names provided"); } + if !args.yes { + let confirmation = Confirm::new() + .with_prompt(format!( + "Are you sure you want to drop the databases?\n\n{}\n\nThis action cannot be undone", + args.name + .iter() + .map(|d| format!("- {}", d)) + .collect::>() + .join("\n") + )) + .interact()?; + + if !confirmation { + println!("Aborting drop operation."); + return Ok(()); + } + } + let message = Request::DropDatabases(args.name.to_owned()); server_connection.send(message).await?; diff --git a/src/client/commands/drop_user.rs b/src/client/commands/drop_user.rs index 5a698c1..f0adb3a 100644 --- a/src/client/commands/drop_user.rs +++ b/src/client/commands/drop_user.rs @@ -1,5 +1,6 @@ use clap::Parser; use clap_complete::ArgValueCompleter; +use dialoguer::Confirm; use futures_util::SinkExt; use tokio_stream::StreamExt; @@ -24,6 +25,10 @@ pub struct DropUserArgs { /// Print the information as JSON #[arg(short, long)] json: bool, + + /// Automatically confirm action without prompting + #[arg(short, long)] + yes: bool, } pub async fn drop_users( @@ -34,6 +39,24 @@ pub async fn drop_users( anyhow::bail!("No usernames provided"); } + if !args.yes { + let confirmation = Confirm::new() + .with_prompt(format!( + "Are you sure you want to drop the users?\n\n{}\n\nThis action cannot be undone", + args.username + .iter() + .map(|d| format!("- {}", d)) + .collect::>() + .join("\n") + )) + .interact()?; + + if !confirmation { + println!("Aborting drop operation."); + return Ok(()); + } + } + let message = Request::DropUsers(args.username.to_owned()); if let Err(err) = server_connection.send(message).await {