Browse Source

feat: add confirmation for logout

main
fdai7374 2 years ago
parent
commit
dfc5ff6759
  1. 6
      src/builtins/logout.rs

6
src/builtins/logout.rs

@ -1,15 +1,21 @@
use crate::builtins::{Builtin, BuiltinConfig}; use crate::builtins::{Builtin, BuiltinConfig};
use crate::error::ShellError; use crate::error::ShellError;
use system_shutdown::logout; use system_shutdown::logout;
use std::io;
pub struct Logout; pub struct Logout;
impl Builtin for Logout { impl Builtin for Logout {
fn execute(&mut self, _: &mut BuiltinConfig, _: Vec<String>) -> Result<(), ShellError> { fn execute(&mut self, _: &mut BuiltinConfig, _: Vec<String>) -> Result<(), ShellError> {
let mut input = String::new();
println!("Are you sure? Unsaved data will be lost.\ny/n");
io::stdin().read_line(&mut input).expect("Couldn't read form stdin");
if input.chars().next().unwrap()=='y' {
match logout() { match logout() {
Ok(_) => println!("Logging out"), Ok(_) => println!("Logging out"),
Err(error) => eprintln!("Failed to log out: {}", error), Err(error) => eprintln!("Failed to log out: {}", error),
} }
}else {println!("Aborting");}
Ok(()) Ok(())
} }
} }
Loading…
Cancel
Save