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", alias = "current")]
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(_) => CommandDescriptor::PROFILE_SECRETS_AND_PATHS.with_skip_validation(),
40            Self::Switch { .. } => CommandDescriptor::PROFILE_AND_SECRETS,
41            Self::Show | Self::List | Self::Logout(_) => CommandDescriptor::NONE,
42        }
43    }
44}
45
46pub async fn execute(cmd: SessionCommands, config: &CliConfig) -> Result<()> {
47    match cmd {
48        SessionCommands::Show => {
49            let result = show::execute(config);
50            render_result(&result);
51            Ok(())
52        },
53        SessionCommands::Switch { profile_name } => {
54            let result = switch::execute(&profile_name, config).await?;
55            render_result(&result);
56            Ok(())
57        },
58        SessionCommands::List => {
59            let result = list::execute(config);
60            render_result(&result);
61            Ok(())
62        },
63        SessionCommands::Login(args) => {
64            let result = login::execute(args, config).await?;
65            render_result(&result);
66            Ok(())
67        },
68        SessionCommands::Logout(ref args) => {
69            let result = logout::execute(args, config)?;
70            render_result(&result);
71            Ok(())
72        },
73    }
74}