Skip to main content

systemprompt_cli/commands/cloud/auth/
mod.rs

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