Skip to content

Commit 931540c

Browse files
refactor(cli): replace promptly with dialoguer
1 parent 9d74aea commit 931540c

File tree

3 files changed

+29
-164
lines changed

3 files changed

+29
-164
lines changed

Cargo.lock

+20-140
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
@@ -39,7 +39,7 @@ chrono = { version = "0.4.19", default-features = false, features = ["clock"] }
3939
anyhow = "1.0.52"
4040
async-trait = "0.1.52"
4141
console = "0.15.0"
42-
promptly = "0.3.0"
42+
dialoguer = "0.11"
4343
serde_json = "1.0.73"
4444
glob = "0.3.0"
4545
openssl = { version = "0.10.38", optional = true }

sqlx-cli/src/database.rs

+8-23
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::migrate;
22
use crate::opt::ConnectOpts;
33
use console::style;
4-
use promptly::{prompt, ReadlineError};
4+
use dialoguer::Confirm;
55
use sqlx::any::Any;
66
use sqlx::migrate::MigrateDatabase;
77

@@ -59,26 +59,11 @@ pub async fn setup(migration_source: &str, connect_opts: &ConnectOpts) -> anyhow
5959
}
6060

6161
fn ask_to_continue_drop(db_url: &str) -> bool {
62-
loop {
63-
let r: Result<String, ReadlineError> =
64-
prompt(format!("Drop database at {}? (y/n)", style(db_url).cyan()));
65-
match r {
66-
Ok(response) => {
67-
if response == "n" || response == "N" {
68-
return false;
69-
} else if response == "y" || response == "Y" {
70-
return true;
71-
} else {
72-
println!(
73-
"Response not recognized: {}\nPlease type 'y' or 'n' and press enter.",
74-
response
75-
);
76-
}
77-
}
78-
Err(e) => {
79-
println!("{e}");
80-
return false;
81-
}
82-
}
83-
}
62+
Confirm::new()
63+
.with_prompt(format!("Drop database at {}?", style(db_url).cyan()))
64+
.wait_for_newline(true)
65+
.default(false)
66+
.show_default(true)
67+
.interact()
68+
.unwrap()
8469
}

0 commit comments

Comments
 (0)