Skip to content

Commit

Permalink
Use dialoger for prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
JesperAxelsson authored and mehcode committed Apr 19, 2020
1 parent f491198 commit 38892c1
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions cargo-sqlx/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use structopt::StructOpt;

use anyhow::{anyhow, Context, Result};
use console::style;
use dialoguer::Confirmation;

mod database_migrator;
mod postgres;
Expand Down Expand Up @@ -133,8 +134,6 @@ async fn run_create_database(migrator: &dyn DatabaseMigrator) -> Result<()> {
}

async fn run_drop_database(migrator: &dyn DatabaseMigrator) -> Result<()> {
use std::io;

if !migrator.can_drop_database() {
return Err(anyhow!(
"Database drop is not implemented for {}",
Expand All @@ -146,24 +145,13 @@ async fn run_drop_database(migrator: &dyn DatabaseMigrator) -> Result<()> {
let db_exists = migrator.check_if_database_exists(&db_name).await?;

if db_exists {
loop {
println!(
"\nAre you sure you want to drop the database: {}? Y/n",
db_name
);

let mut input = String::new();

io::stdin()
.read_line(&mut input)
.context("Failed to read line")?;

match input.trim() {
"Y" => break,
"N" => return Ok(()),
"n" => return Ok(()),
_ => continue,
};
if !Confirmation::new()
.with_text("\nAre you sure you want to drop the database: {}?")
.default(false)
.interact()?
{
println!("Aborting");
return Ok(());
}

println!("Dropping database: {}", db_name);
Expand Down

0 comments on commit 38892c1

Please sign in to comment.