Skip to content

Commit

Permalink
refactor(cli): replace promptly with dialoguer
Browse files Browse the repository at this point in the history
  • Loading branch information
paolobarbolini committed Jan 6, 2025
1 parent 9d74aea commit 931540c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 164 deletions.
160 changes: 20 additions & 140 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sqlx-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ chrono = { version = "0.4.19", default-features = false, features = ["clock"] }
anyhow = "1.0.52"
async-trait = "0.1.52"
console = "0.15.0"
promptly = "0.3.0"
dialoguer = "0.11"
serde_json = "1.0.73"
glob = "0.3.0"
openssl = { version = "0.10.38", optional = true }
Expand Down
31 changes: 8 additions & 23 deletions sqlx-cli/src/database.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::migrate;
use crate::opt::ConnectOpts;
use console::style;
use promptly::{prompt, ReadlineError};
use dialoguer::Confirm;
use sqlx::any::Any;
use sqlx::migrate::MigrateDatabase;

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

fn ask_to_continue_drop(db_url: &str) -> bool {
loop {
let r: Result<String, ReadlineError> =
prompt(format!("Drop database at {}? (y/n)", style(db_url).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;
}
}
}
Confirm::new()
.with_prompt(format!("Drop database at {}?", style(db_url).cyan()))
.wait_for_newline(true)
.default(false)
.show_default(true)
.interact()
.unwrap()
}

0 comments on commit 931540c

Please sign in to comment.