You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

30 lines
947 B

use crate::builtins::{Builtin, BuiltinConfig};
use crate::error::ShellError;
use std::io;
use system_shutdown::logout;
pub struct Logout;
impl Builtin for Logout {
fn execute(&mut self, _: &mut BuiltinConfig, _: Vec<String>) -> Result<(), ShellError> {
let mut input_confirmation = String::new();
println!("Are you sure? Unsaved data will be lost.\ny/n");
match io::stdin().read_line(&mut input_confirmation) {
Ok(_) => {}
Err(e) => {
return Err(ShellError::ExecuteFailure(format!(
"Couldn't read from stdin. {e}",
)));
}
}
if input_confirmation.starts_with('y') {
match logout() {
Ok(_) => println!("Logging out"),
Err(error) => eprintln!("Failed to log out: {error}"),
}
} else {
println!("Aborting");
}
Ok(())
}
}