mirror of
https://github.com/launchbadge/sqlx.git
synced 2026-03-19 08:39:44 +00:00
Use promptly instead of dialoguer (#1410)
See #1409 Co-authored-by: David James <davidcjames@gmail.com>
This commit is contained in:
@@ -44,7 +44,7 @@ anyhow = "1.0"
|
||||
url = { version = "2.1.1", default-features = false }
|
||||
async-trait = "0.1.30"
|
||||
console = "0.14.1"
|
||||
dialoguer = "0.8.0"
|
||||
promptly = "0.3.0"
|
||||
serde_json = "1.0.53"
|
||||
serde = { version = "1.0.110", features = ["derive"] }
|
||||
glob = "0.3.0"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::migrate;
|
||||
use console::style;
|
||||
use dialoguer::Confirm;
|
||||
use promptly::{prompt, ReadlineError};
|
||||
use sqlx::any::Any;
|
||||
use sqlx::migrate::MigrateDatabase;
|
||||
|
||||
@@ -13,16 +13,7 @@ pub async fn create(uri: &str) -> anyhow::Result<()> {
|
||||
}
|
||||
|
||||
pub async fn drop(uri: &str, confirm: bool) -> anyhow::Result<()> {
|
||||
if confirm
|
||||
&& !Confirm::new()
|
||||
.with_prompt(format!(
|
||||
"\nAre you sure you want to drop the database at {}?",
|
||||
style(uri).cyan()
|
||||
))
|
||||
.wait_for_newline(true)
|
||||
.default(false)
|
||||
.interact()?
|
||||
{
|
||||
if confirm && !ask_to_continue(uri) {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -42,3 +33,28 @@ pub async fn setup(migration_source: &str, uri: &str) -> anyhow::Result<()> {
|
||||
create(uri).await?;
|
||||
migrate::run(migration_source, uri, false, false).await
|
||||
}
|
||||
|
||||
fn ask_to_continue(uri: &str) -> bool {
|
||||
loop {
|
||||
let r: Result<String, ReadlineError> =
|
||||
prompt(format!("Drop database at {}? (y/n)", style(uri).cyan()));
|
||||
match r {
|
||||
Ok(response) => {
|
||||
if response == "n" || response == "N" {
|
||||
return false;
|
||||
} else if response == "y" || response == "Y" {
|
||||
return true;
|
||||
} else {
|
||||
println!(
|
||||
"Response not recognized: {}\nPlease type 'y' or 'n' and press enter.",
|
||||
response
|
||||
);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
println!("{}", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user