Skip to main content

systemprompt_cli/commands/admin/session/
mod.rs

1//! Session management commands.
2
3mod list;
4pub mod login;
5mod login_helpers;
6mod logout;
7mod show;
8mod switch;
9pub mod types;
10
11use anyhow::Result;
12use clap::Subcommand;
13
14use crate::cli_settings::CliConfig;
15use crate::descriptor::{CommandDescriptor, DescribeCommand};
16use crate::shared::render_result;
17
18#[derive(Debug, Subcommand)]
19pub enum SessionCommands {
20    #[command(about = "Show current session and routing info")]
21    Show,
22
23    #[command(about = "Switch to a different profile")]
24    Switch { profile_name: String },
25
26    #[command(about = "List available profiles")]
27    List,
28
29    #[command(about = "Create an admin session for CLI access")]
30    Login(login::LoginArgs),
31
32    #[command(about = "Remove a session")]
33    Logout(logout::LogoutArgs),
34}
35
36impl DescribeCommand for SessionCommands {
37    fn descriptor(&self) -> CommandDescriptor {
38        match self {
39            Self::Login(_) | Self::Switch { .. } => CommandDescriptor::PROFILE_AND_SECRETS,
40            Self::Show | Self::List | Self::Logout(_) => CommandDescriptor::NONE,
41        }
42    }
43}
44
45pub async fn execute(cmd: SessionCommands, config: &CliConfig) -> Result<()> {
46    match cmd {
47        SessionCommands::Show => {
48            let result = show::execute(config);
49            render_result(&result);
50            Ok(())
51        },
52        SessionCommands::Switch { profile_name } => {
53            let result = switch::execute(&profile_name, config).await?;
54            render_result(&result);
55            Ok(())
56        },
57        SessionCommands::List => {
58            let result = list::execute(config);
59            render_result(&result);
60            Ok(())
61        },
62        SessionCommands::Login(args) => {
63            let result = login::execute(args, config).await?;
64            render_result(&result);
65            Ok(())
66        },
67        SessionCommands::Logout(ref args) => {
68            let result = logout::execute(args, config)?;
69            render_result(&result);
70            Ok(())
71        },
72    }
73}