mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-13 15:30:03 +00:00
Refactor: Extract confirm
into a new mod
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
f53680c497
commit
c1809d41fa
2 changed files with 26 additions and 18 deletions
21
src/helpers/confirm.rs
Normal file
21
src/helpers/confirm.rs
Normal file
|
@ -0,0 +1,21 @@
|
|||
use log::info;
|
||||
use std::io::{stderr, stdin, Write};
|
||||
|
||||
use crate::BinstallError;
|
||||
|
||||
pub fn confirm() -> Result<(), BinstallError> {
|
||||
loop {
|
||||
info!("Do you wish to continue? yes/[no]");
|
||||
eprint!("? ");
|
||||
stderr().flush().ok();
|
||||
|
||||
let mut input = String::new();
|
||||
stdin().read_line(&mut input).unwrap();
|
||||
|
||||
match input.as_str().trim() {
|
||||
"yes" | "y" | "YES" | "Y" => break Ok(()),
|
||||
"no" | "n" | "NO" | "N" | "" => break Err(BinstallError::UserAbort),
|
||||
_ => continue,
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue