Add --yes flag for drop operations
All checks were successful
All checks were successful
This commit is contained in:
@@ -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?;
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user