mirror of
https://github.com/launchbadge/sqlx
synced 2024-11-10 06:24:16 +00:00
Use promptly instead of dialoguer (#1410)
See #1409 Co-authored-by: David James <davidcjames@gmail.com>
This commit is contained in:
parent
0e51272b72
commit
ad81e35f28
3 changed files with 97 additions and 26 deletions
83
Cargo.lock
generated
83
Cargo.lock
generated
|
@ -665,18 +665,6 @@ dependencies = [
|
|||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dialoguer"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c9dd058f8b65922819fabb4a41e7d1964e56344042c26efbccd465202c23fa0c"
|
||||
dependencies = [
|
||||
"console",
|
||||
"lazy_static",
|
||||
"tempfile",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "difference"
|
||||
version = "2.0.0"
|
||||
|
@ -701,6 +689,16 @@ dependencies = [
|
|||
"dirs-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs-next"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf36e65a80337bea855cd4ef9b8401ffce06a7baedf2e85ec467b1ac3f6e82b6"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"dirs-sys-next",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs-sys"
|
||||
version = "0.3.6"
|
||||
|
@ -712,6 +710,17 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs-sys-next"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"redox_users",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "discard"
|
||||
version = "1.0.4"
|
||||
|
@ -1289,7 +1298,7 @@ version = "1.1.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6d9bb26482176bddeea173ceaa2acec85146d20cdcc631eafaf9d605d3d4fc23"
|
||||
dependencies = [
|
||||
"nix",
|
||||
"nix 0.19.1",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
|
@ -1398,6 +1407,18 @@ dependencies = [
|
|||
"tempfile",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nix"
|
||||
version = "0.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "83450fe6a6142ddd95fb064b746083fc4ef1705fe81f64a64e1d4b39f54a1055"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cc",
|
||||
"cfg-if 0.1.10",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nix"
|
||||
version = "0.19.1"
|
||||
|
@ -1815,6 +1836,15 @@ dependencies = [
|
|||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "promptly"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b99cfb0289110d969dd21637cfbc922584329bc9e5037c5e576325c615658509"
|
||||
dependencies = [
|
||||
"rustyline",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quick-error"
|
||||
version = "1.2.3"
|
||||
|
@ -2045,6 +2075,25 @@ dependencies = [
|
|||
"webpki",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustyline"
|
||||
version = "6.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6f0d5e7b0219a3eadd5439498525d4765c59b7c993ef0c12244865cd2d988413"
|
||||
dependencies = [
|
||||
"cfg-if 0.1.10",
|
||||
"dirs-next",
|
||||
"libc",
|
||||
"log",
|
||||
"memchr",
|
||||
"nix 0.18.0",
|
||||
"scopeguard",
|
||||
"unicode-segmentation",
|
||||
"unicode-width",
|
||||
"utf8parse",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.5"
|
||||
|
@ -2331,11 +2380,11 @@ dependencies = [
|
|||
"clap 3.0.0-beta.2",
|
||||
"clap_derive",
|
||||
"console",
|
||||
"dialoguer",
|
||||
"dotenv",
|
||||
"futures",
|
||||
"glob",
|
||||
"openssl",
|
||||
"promptly",
|
||||
"remove_dir_all 0.7.0",
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
@ -2982,6 +3031,12 @@ dependencies = [
|
|||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "utf8parse"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "936e4b492acfd135421d8dca4b1aa80a7bfc26e702ef3af710e0752684df5372"
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "0.8.2"
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue