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(
24        about = "Show current authenticated user and token status",
25        alias = "status"
26    )]
27    Whoami,
28}
29
30#[derive(Debug, Clone, Copy, Args)]
31pub struct LogoutArgs {
32    #[arg(short = 'y', long, help = "Skip confirmation prompts")]
33    pub yes: bool,
34}
35
36pub async fn execute(cmd: AuthCommands, config: &CliConfig) -> Result<()> {
37    match cmd {
38        AuthCommands::Login { environment } => {
39            let result = login::execute(environment, config).await?;
40            render_result(&result);
41            Ok(())
42        },
43        AuthCommands::Logout(args) => {
44            let result = logout::execute(args, config).await?;
45            render_result(&result);
46            Ok(())
47        },
48        AuthCommands::Whoami => {
49            let result = whoami::execute(config).await?;
50            render_result(&result);
51            Ok(())
52        },
53    }
54}