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