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