Skip to main content

systemprompt_cli/commands/admin/session/
mod.rs

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