Skip to content

Commit ad81e35

Browse files
xpeDavid James
and
David James
authored
Use promptly instead of dialoguer (#1410)
See #1409 Co-authored-by: David James <[email protected]>
1 parent 0e51272 commit ad81e35

File tree

3 files changed

+97
-26
lines changed

3 files changed

+97
-26
lines changed

Cargo.lock

+69-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sqlx-cli/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ anyhow = "1.0"
4444
url = { version = "2.1.1", default-features = false }
4545
async-trait = "0.1.30"
4646
console = "0.14.1"
47-
dialoguer = "0.8.0"
47+
promptly = "0.3.0"
4848
serde_json = "1.0.53"
4949
serde = { version = "1.0.110", features = ["derive"] }
5050
glob = "0.3.0"

sqlx-cli/src/database.rs

+27-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::migrate;
22
use console::style;
3-
use dialoguer::Confirm;
3+
use promptly::{prompt, ReadlineError};
44
use sqlx::any::Any;
55
use sqlx::migrate::MigrateDatabase;
66

@@ -13,16 +13,7 @@ pub async fn create(uri: &str) -> anyhow::Result<()> {
1313
}
1414

1515
pub async fn drop(uri: &str, confirm: bool) -> anyhow::Result<()> {
16-
if confirm
17-
&& !Confirm::new()
18-
.with_prompt(format!(
19-
"\nAre you sure you want to drop the database at {}?",
20-
style(uri).cyan()
21-
))
22-
.wait_for_newline(true)
23-
.default(false)
24-
.interact()?
25-
{
16+
if confirm && !ask_to_continue(uri) {
2617
return Ok(());
2718
}
2819

@@ -42,3 +33,28 @@ pub async fn setup(migration_source: &str, uri: &str) -> anyhow::Result<()> {
4233
create(uri).await?;
4334
migrate::run(migration_source, uri, false, false).await
4435
}
36+
37+
fn ask_to_continue(uri: &str) -> bool {
38+
loop {
39+
let r: Result<String, ReadlineError> =
40+
prompt(format!("Drop database at {}? (y/n)", style(uri).cyan()));
41+
match r {
42+
Ok(response) => {
43+
if response == "n" || response == "N" {
44+
return false;
45+
} else if response == "y" || response == "Y" {
46+
return true;
47+
} else {
48+
println!(
49+
"Response not recognized: {}\nPlease type 'y' or 'n' and press enter.",
50+
response
51+
);
52+
}
53+
}
54+
Err(e) => {
55+
println!("{}", e);
56+
return false;
57+
}
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)