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//!
6//! Copyright (c) systemprompt.io — Business Source License 1.1.
7//! See <https://systemprompt.io> for licensing details.
8
9mod login;
10mod logout;
11mod whoami;
12
13pub use login::complete_login;
14
15use crate::context::CommandContext;
16use crate::shared::render_result;
17use anyhow::Result;
18use clap::{Args, Subcommand};
19
20use super::Environment;
21
22#[derive(Debug, Clone, Copy, Subcommand)]
23pub enum AuthCommands {
24    #[command(about = "Authenticate with systemprompt.io Cloud via OAuth")]
25    Login {
26        #[arg(value_enum, default_value_t = Environment::default(), hide = true)]
27        environment: Environment,
28    },
29
30    #[command(about = "Clear saved cloud credentials")]
31    Logout(LogoutArgs),
32
33    #[command(
34        about = "Show current authenticated user and token status",
35        alias = "status"
36    )]
37    Whoami,
38}
39
40#[derive(Debug, Clone, Copy, Args)]
41pub struct LogoutArgs {
42    #[arg(short = 'y', long, help = "Skip confirmation prompts")]
43    pub yes: bool,
44}
45
46pub async fn execute(cmd: AuthCommands, ctx: &CommandContext) -> Result<()> {
47    match cmd {
48        AuthCommands::Login { environment } => {
49            let result = login::execute(environment, ctx.prompter(), &ctx.cli).await?;
50            render_result(&result, &ctx.cli);
51            Ok(())
52        },
53        AuthCommands::Logout(args) => {
54            let result = logout::execute(args, ctx.prompter(), &ctx.cli).await?;
55            render_result(&result, &ctx.cli);
56            Ok(())
57        },
58        AuthCommands::Whoami => {
59            let result = whoami::execute(&ctx.cli).await?;
60            render_result(&result, &ctx.cli);
61            Ok(())
62        },
63    }
64}