diff --git a/src/prompt.rs b/src/prompt.rs index 1db632a..152e81f 100644 --- a/src/prompt.rs +++ b/src/prompt.rs @@ -31,7 +31,7 @@ pub async fn prompt(client: Client) -> anyhow::Result<()> { if let Some(cmd) = args.get(0) { match cmd.as_ref() { "help" => { - println!("help; stop; rooms; join room_id; leave room_id"); + println!("help; stop; logout; rooms; join room_id; leave room_id"); }, "stop" => { let should_stop = unsafe { crate::SHOULD_STOP.get_mut() }; @@ -40,6 +40,19 @@ pub async fn prompt(client: Client) -> anyhow::Result<()> { eprintln!("Stopping..."); } }, + "logout" => { + match client.logout().await { + Ok(_) => { + println!("Logged out."); + match std::fs::remove_dir_all(crate::DATA_DIR.to_owned()) { + Ok(_) => (), + Err(e) => anyhow::bail!("Couldn't remove data dir: {e}"), + } + std::process::exit(0); + }, + Err(e) => anyhow::bail!("Failed to logout: {e}") + } + }, "rooms" => { let rooms = client.rooms();