How to use dialoguer for interactive CLI

Cli
Use dialoguer::Confirm with task::spawn_blocking to safely prompt users for yes/no confirmation in async Rust CLI applications.

Use dialoguer::Confirm to create a prompt that asks the user for a yes/no decision before executing destructive actions like dropping a database. The sqlx-cli implementation spawns this interaction on a blocking thread to prevent blocking the async runtime while waiting for user input.

use dialoguer::Confirm;
use tokio::task;

async fn ask_to_continue_drop(db_url: String) -> bool {
    let decision_result = task::spawn_blocking(move || {
        Confirm::new()
            .with_prompt(format!("Drop database at {}?", db_url))
            .wait_for_newline(true)
            .default(false)
            .show_default(true)
            .interact()
    })
    .await
    .expect("Confirm thread panicked");

    match decision_result {
        Ok(decision) => decision,
        Err(_) => false,
    }
}