codeberg_cli/actions/auth/
logout.rs

1use crate::actions::GeneralArgs;
2use crate::paths::token_path;
3use crate::render::ui::confirm_with_prompt;
4use crate::types::context::BergContext;
5
6use anyhow::Context;
7use clap::Parser;
8
9/// Logout. Delete currently stored authentication token
10#[derive(Parser, Debug)]
11pub struct LogoutArgs {
12    /// flag that skips the confirmation dialog if set
13    #[arg(short, long)]
14    pub skip_confirmation: bool,
15}
16
17impl LogoutArgs {
18    pub async fn run(self, general_args: GeneralArgs) -> anyhow::Result<()> {
19        let _ = general_args;
20        let ctx = BergContext::new(self, general_args).await?;
21        if !ctx.args.skip_confirmation
22            && !confirm_with_prompt(
23                "Logging out deletes your current token. Do you want to proceed?",
24            )?
25        {
26            return Ok(());
27        }
28
29        let token_path = token_path()?;
30
31        std::fs::remove_file(token_path).context("Failed to remove token!")?;
32
33        Ok(())
34    }
35}