Add logout command

This commit is contained in:
0xf8 2023-04-21 15:43:20 -04:00
parent 9a14cb6c90
commit 1c5565e0fb
Signed by: 0xf8
GPG Key ID: 446580D758689584

View File

@ -31,7 +31,7 @@ pub async fn prompt(client: Client) -> anyhow::Result<()> {
if let Some(cmd) = args.get(0) { if let Some(cmd) = args.get(0) {
match cmd.as_ref() { match cmd.as_ref() {
"help" => { "help" => {
println!("help; stop; rooms; join room_id; leave room_id"); println!("help; stop; logout; rooms; join room_id; leave room_id");
}, },
"stop" => { "stop" => {
let should_stop = unsafe { crate::SHOULD_STOP.get_mut() }; let should_stop = unsafe { crate::SHOULD_STOP.get_mut() };
@ -40,6 +40,19 @@ pub async fn prompt(client: Client) -> anyhow::Result<()> {
eprintln!("Stopping..."); 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" => { "rooms" => {
let rooms = client.rooms(); let rooms = client.rooms();