git_stk/prompt.rs
1use std::io::{self, BufRead, Write};
2
3use anyhow::{Context, Result};
4
5pub fn confirm(prompt: &str) -> Result<bool> {
6 print!("{prompt}");
7 io::stdout().flush().context("failed to flush stdout")?;
8
9 let mut answer = String::new();
10 io::stdin()
11 .lock()
12 .read_line(&mut answer)
13 .context("failed to read confirmation")?;
14
15 Ok(matches!(answer.trim(), "y" | "Y" | "yes" | "Yes" | "YES"))
16}