Skip to main content

systemprompt_cli/commands/admin/users/
mod.rs

1mod ban;
2mod bulk;
3mod count;
4mod create;
5mod delete;
6mod export;
7mod list;
8mod merge;
9mod role;
10mod search;
11mod session;
12mod show;
13mod stats;
14mod types;
15mod update;
16
17use crate::cli_settings::CliConfig;
18use anyhow::{bail, Result};
19use clap::Subcommand;
20use systemprompt_runtime::DatabaseContext;
21
22pub use types::*;
23
24#[derive(Debug, Subcommand)]
25pub enum UsersCommands {
26    #[command(about = "List users with pagination and filtering")]
27    List(list::ListArgs),
28
29    #[command(about = "Show detailed user information")]
30    Show(show::ShowArgs),
31
32    #[command(about = "Search users by name, email, or full name")]
33    Search(search::SearchArgs),
34
35    #[command(about = "Create a new user")]
36    Create(create::CreateArgs),
37
38    #[command(about = "Update user fields")]
39    Update(update::UpdateArgs),
40
41    #[command(about = "Delete a user")]
42    Delete(delete::DeleteArgs),
43
44    #[command(about = "Get total user count")]
45    Count(count::CountArgs),
46
47    #[command(about = "Export users to JSON")]
48    Export(export::ExportArgs),
49
50    #[command(about = "Show user statistics dashboard")]
51    Stats,
52
53    #[command(about = "Merge source user into target user")]
54    Merge(merge::MergeArgs),
55
56    #[command(subcommand, about = "Bulk operations on users")]
57    Bulk(bulk::BulkCommands),
58
59    #[command(subcommand, about = "Role management commands")]
60    Role(role::RoleCommands),
61
62    #[command(subcommand, about = "Session management commands")]
63    Session(session::SessionCommands),
64
65    #[command(subcommand, about = "IP ban management commands")]
66    Ban(ban::BanCommands),
67}
68
69pub async fn execute(cmd: UsersCommands, config: &CliConfig) -> Result<()> {
70    match cmd {
71        UsersCommands::List(args) => list::execute(args, config).await,
72        UsersCommands::Show(args) => show::execute(args, config).await,
73        UsersCommands::Search(args) => search::execute(args, config).await,
74        UsersCommands::Create(args) => create::execute(args, config).await,
75        UsersCommands::Update(args) => update::execute(args, config).await,
76        UsersCommands::Delete(args) => delete::execute(args, config).await,
77        UsersCommands::Count(args) => count::execute(args, config).await,
78        UsersCommands::Export(args) => export::execute(args, config).await,
79        UsersCommands::Stats => stats::execute(config).await,
80        UsersCommands::Merge(args) => merge::execute(args, config).await,
81        UsersCommands::Bulk(cmd) => bulk::execute(cmd, config).await,
82        UsersCommands::Role(cmd) => role::execute(cmd, config).await,
83        UsersCommands::Session(cmd) => session::execute(cmd, config).await,
84        UsersCommands::Ban(cmd) => ban::execute(cmd, config).await,
85    }
86}
87
88pub async fn execute_with_db(
89    cmd: UsersCommands,
90    db_ctx: &DatabaseContext,
91    config: &CliConfig,
92) -> Result<()> {
93    match cmd {
94        UsersCommands::List(args) => list::execute_with_pool(args, db_ctx.db_pool(), config).await,
95        UsersCommands::Show(args) => show::execute_with_pool(args, db_ctx.db_pool(), config).await,
96        UsersCommands::Search(args) => {
97            search::execute_with_pool(args, db_ctx.db_pool(), config).await
98        },
99        UsersCommands::Count(args) => {
100            count::execute_with_pool(args, db_ctx.db_pool(), config).await
101        },
102        UsersCommands::Export(args) => {
103            export::execute_with_pool(args, db_ctx.db_pool(), config).await
104        },
105        UsersCommands::Stats => stats::execute_with_pool(db_ctx.db_pool(), config).await,
106        UsersCommands::Session(cmd) => {
107            session::execute_with_pool(cmd, db_ctx.db_pool(), config).await
108        },
109        UsersCommands::Ban(cmd) => ban::execute_with_pool(cmd, db_ctx.db_pool(), config).await,
110        UsersCommands::Role(cmd) => role::execute_with_pool(cmd, db_ctx.db_pool(), config),
111        UsersCommands::Create(_)
112        | UsersCommands::Update(_)
113        | UsersCommands::Delete(_)
114        | UsersCommands::Merge(_)
115        | UsersCommands::Bulk(_) => {
116            bail!("Write operations require full profile context")
117        },
118    }
119}