Skip to main content

systemprompt_cli/commands/cloud/auth/
mod.rs

1mod login;
2mod logout;
3mod whoami;
4
5use crate::cli_settings::CliConfig;
6use crate::shared::render_result;
7use anyhow::Result;
8use clap::{Args, Subcommand};
9
10use super::Environment;
11
12#[derive(Debug, Clone, Copy, Subcommand)]
13pub enum AuthCommands {
14    #[command(about = "Authenticate with systemprompt.io Cloud via OAuth")]
15    Login {
16        #[arg(value_enum, default_value_t = Environment::default(), hide = true)]
17        environment: Environment,
18    },
19
20    #[command(about = "Clear saved cloud credentials")]
21    Logout(LogoutArgs),
22
23    #[command(about = "Show current authenticated user and token status")]
24    Whoami,
25}
26
27#[derive(Debug, Clone, Copy, Args)]
28pub struct LogoutArgs {
29    #[arg(short = 'y', long, help = "Skip confirmation prompts")]
30    pub yes: bool,
31}
32
33pub async fn execute(cmd: AuthCommands, config: &CliConfig) -> Result<()> {
34    match cmd {
35        AuthCommands::Login { environment } => {
36            let result = login::execute(environment, config).await?;
37            render_result(&result);
38            Ok(())
39        },
40        AuthCommands::Logout(args) => {
41            let result = logout::execute(args, config).await?;
42            render_result(&result);
43            Ok(())
44        },
45        AuthCommands::Whoami => {
46            let result = whoami::execute(config).await?;
47            render_result(&result);
48            Ok(())
49        },
50    }
51}