Skip to main content

systemprompt_cli/commands/infrastructure/
mod.rs

1//! `infra` command group: services, database, jobs, and logs administration.
2//!
3//! Routes [`InfraCommands`] to the per-domain subcommand modules. [`execute`]
4//! is the standalone entry point; [`execute_with_db`] reuses an open
5//! [`DatabaseContext`] for the db and logs subtrees that only need a pool.
6
7pub mod db;
8pub mod jobs;
9pub mod logs;
10pub mod services;
11
12use anyhow::Result;
13use clap::Subcommand;
14use systemprompt_runtime::DatabaseContext;
15
16use crate::CliConfig;
17
18#[derive(Debug, Subcommand)]
19pub enum InfraCommands {
20    #[command(
21        subcommand,
22        about = "Service lifecycle management (start, stop, status)"
23    )]
24    Services(services::ServicesCommands),
25
26    #[command(subcommand, about = "Database operations and administration")]
27    Db(db::DbCommands),
28
29    #[command(subcommand, about = "Background jobs and scheduling")]
30    Jobs(jobs::JobsCommands),
31
32    #[command(subcommand, about = "Log streaming and tracing")]
33    Logs(logs::LogsCommands),
34}
35
36pub async fn execute(cmd: InfraCommands, config: &CliConfig) -> Result<()> {
37    match cmd {
38        InfraCommands::Services(cmd) => services::execute(cmd, config).await,
39        InfraCommands::Db(cmd) => db::execute(cmd, config).await,
40        InfraCommands::Jobs(cmd) => jobs::execute(cmd, config).await,
41        InfraCommands::Logs(cmd) => logs::execute(cmd, config).await,
42    }
43}
44
45pub async fn execute_with_db(
46    cmd: InfraCommands,
47    db_ctx: &DatabaseContext,
48    config: &CliConfig,
49) -> Result<()> {
50    match cmd {
51        InfraCommands::Db(cmd) => db::execute_with_db(cmd, db_ctx, config).await,
52        InfraCommands::Logs(cmd) => logs::execute_with_db(cmd, db_ctx, config).await,
53        _ => anyhow::bail!("This command requires full profile context"),
54    }
55}