From 1c5565e0fb807d3022e6658ee0ce15bd65743fef Mon Sep 17 00:00:00 2001 From: 0xf8 <0xf8.dev@proton.me> Date: Fri, 21 Apr 2023 15:43:20 -0400 Subject: [PATCH] Add logout command --- src/prompt.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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();