diff --git a/src/main.rs b/src/main.rs index 1a6dd85..4a278f1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -116,7 +116,12 @@ fn main() { if value.is_empty() { exit!("'rm' value: [DOMAIN | IP]"); } - log!("todo"); + match ask("Confirm delete? Y/N\n") { + Ok(d) => { + log!("todo"); + } + Err(err) => exit!("{:?}", err), + } } } "ls" => { @@ -190,6 +195,22 @@ fn main() { task::block_on(watch_config(config_path)); } +fn ask(tips: &str) -> io::Result { + use std::io; + use std::io::Write; + io::stdout().write(tips.as_bytes())?; + io::stdout().flush()?; + + let mut s = String::new(); + io::stdin().read_line(&mut s)?; + + return match s.to_uppercase().as_str() { + "Y\n" => Ok(true), + "N\n" => Ok(false), + _ => Ok(ask(&tips)?), + }; +} + fn update_config(mut proxy: Vec, hosts: Hosts) { if proxy.is_empty() { proxy = DEFAULT_PROXY