Add --yes flag for drop operations
All checks were successful
Build and test / check (push) Successful in 2m23s
Build and test / build (push) Successful in 3m5s
Build and test / check-license (push) Successful in 5m31s
Build and test / test (push) Successful in 4m0s
Build and test / docs (push) Successful in 4m46s

This commit is contained in:
2025-12-03 14:21:09 +09:00
parent 6aceda6f3d
commit 6a4a83367e
2 changed files with 46 additions and 0 deletions

View File

@@ -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::<Vec<_>>()
.join("\n")
))
.interact()?;
if !confirmation {
println!("Aborting drop operation.");
return Ok(());
}
}
let message = Request::DropDatabases(args.name.to_owned());
server_connection.send(message).await?;

View File

@@ -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::<Vec<_>>()
.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 {