use std::io::Write;
use anyhow::Result;
use clap::{ArgMatches, Command};
use termcolor::{ColorChoice, StandardStream, WriteColor};
use crate::{
CliCommand,
core::{accounts, command::command},
};
pub(super) struct LogoutCommand;
impl LogoutCommand {
pub(super) fn new() -> Self {
Self {}
}
}
impl CliCommand for LogoutCommand {
fn command(&self) -> Command {
command("logout", "Log out of the forklaunch platform")
}
fn handler(&self, _matches: &ArgMatches) -> Result<()> {
let mut stdout = StandardStream::stdout(ColorChoice::Always);
let selection = accounts::selection()?;
accounts::logout(&accounts::forklaunch_dir()?, &selection)?;
match &selection.name {
Some(name) => log_ok!(stdout, "Logged out of account '{}'.", name),
None => log_ok!(stdout, "Successfully logged out!"),
}
Ok(())
}
}