add ask fn
This commit is contained in:
21
src/main.rs
21
src/main.rs
@@ -116,8 +116,13 @@ fn main() {
|
|||||||
if value.is_empty() {
|
if value.is_empty() {
|
||||||
exit!("'rm' value: [DOMAIN | IP]");
|
exit!("'rm' value: [DOMAIN | IP]");
|
||||||
}
|
}
|
||||||
|
match ask("Confirm delete? Y/N\n") {
|
||||||
|
Ok(d) => {
|
||||||
log!("todo");
|
log!("todo");
|
||||||
}
|
}
|
||||||
|
Err(err) => exit!("{:?}", err),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
"ls" => {
|
"ls" => {
|
||||||
let (_, _, _, mut hosts) = config_parse(&config_path);
|
let (_, _, _, mut hosts) = config_parse(&config_path);
|
||||||
@@ -190,6 +195,22 @@ fn main() {
|
|||||||
task::block_on(watch_config(config_path));
|
task::block_on(watch_config(config_path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn ask(tips: &str) -> io::Result<bool> {
|
||||||
|
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<SocketAddr>, hosts: Hosts) {
|
fn update_config(mut proxy: Vec<SocketAddr>, hosts: Hosts) {
|
||||||
if proxy.is_empty() {
|
if proxy.is_empty() {
|
||||||
proxy = DEFAULT_PROXY
|
proxy = DEFAULT_PROXY
|
||||||
|
|||||||
Reference in New Issue
Block a user