diff --git a/src/helpers.rs b/src/helpers.rs index 679328cd..9b71d3e1 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -1,10 +1,11 @@ use std::{ + borrow::Cow, io::{stderr, stdin, Write}, path::{Path, PathBuf}, }; use cargo_toml::Manifest; -use log::{debug, info}; +use log::debug; use reqwest::Method; use serde::Serialize; use tinytemplate::TinyTemplate; @@ -18,6 +19,9 @@ pub use async_extracter::extract_archive_stream; mod auto_abort_join_handle; pub use auto_abort_join_handle::AutoAbortJoinHandle; +mod confirm; +pub use confirm::confirm; + mod extracter; mod readable_rx; @@ -129,23 +133,6 @@ pub fn get_install_path>(install_path: Option

) -> Option 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, - } - } -} - pub trait Template: Serialize { fn render(&self, template: &str) -> Result where diff --git a/src/helpers/confirm.rs b/src/helpers/confirm.rs new file mode 100644 index 00000000..8872bc2b --- /dev/null +++ b/src/helpers/confirm.rs @@ -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, + } + } +}