systemprompt_cli/commands/infrastructure/
mod.rs1pub mod db;
11pub mod jobs;
12pub mod logs;
13pub mod services;
14
15use anyhow::Result;
16use clap::Subcommand;
17
18use crate::context::CommandContext;
19use crate::descriptor::DataImpact;
20
21#[derive(Debug, Subcommand)]
22pub enum InfraCommands {
23 #[command(
24 subcommand,
25 about = "Service lifecycle management (start, stop, status)"
26 )]
27 Services(services::ServicesCommands),
28
29 #[command(subcommand, about = "Database operations and administration")]
30 Db(db::DbCommands),
31
32 #[command(subcommand, about = "Background jobs and scheduling")]
33 Jobs(jobs::JobsCommands),
34
35 #[command(subcommand, about = "Log streaming and tracing")]
36 Logs(logs::LogsCommands),
37}
38
39pub async fn execute(cmd: InfraCommands, ctx: &CommandContext) -> Result<()> {
40 if ctx.is_database_scoped()
41 && !matches!(
42 cmd,
43 InfraCommands::Db(_)
44 | InfraCommands::Logs(_)
45 | InfraCommands::Jobs(
46 jobs::JobsCommands::List
47 | jobs::JobsCommands::Show(_)
48 | jobs::JobsCommands::History(_)
49 )
50 )
51 {
52 return Err(crate::shared::database_scoped_command_error());
53 }
54
55 match cmd {
56 InfraCommands::Services(cmd) => services::execute(cmd, ctx).await,
57 InfraCommands::Db(cmd) => db::execute(cmd, ctx).await,
58 InfraCommands::Jobs(cmd) => jobs::execute(cmd, ctx).await,
59 InfraCommands::Logs(cmd) => logs::execute(cmd, ctx).await,
60 }
61}
62
63impl InfraCommands {
64 pub const fn data_impact(&self) -> DataImpact {
65 use db::DbCommands;
66 use jobs::JobsCommands;
67 use logs::LogsCommands;
68 use services::ServicesCommands;
69
70 match self {
71 Self::Db(
72 DbCommands::Execute { .. }
73 | DbCommands::Migrate { .. }
74 | DbCommands::MigrateDown { .. }
75 | DbCommands::MigrateRepair { .. }
76 | DbCommands::MigrateMarkApplied { .. }
77 | DbCommands::AssignAdmin { .. },
78 )
79 | Self::Jobs(JobsCommands::Run(_))
80 | Self::Logs(LogsCommands::Cleanup(_) | LogsCommands::Delete(_)) => {
81 DataImpact::Destructive
82 },
83 Self::Db(
84 DbCommands::Query { .. }
85 | DbCommands::Tables { .. }
86 | DbCommands::Describe { .. }
87 | DbCommands::Info
88 | DbCommands::Migrations { .. }
89 | DbCommands::MigratePlan { .. }
90 | DbCommands::MigrateStatus { .. }
91 | DbCommands::Status
92 | DbCommands::Count { .. }
93 | DbCommands::Indexes { .. }
94 | DbCommands::Size
95 | DbCommands::Doctor,
96 )
97 | Self::Jobs(
98 JobsCommands::List
99 | JobsCommands::Show(_)
100 | JobsCommands::History(_)
101 | JobsCommands::Enable(_)
102 | JobsCommands::Disable(_),
103 )
104 | Self::Logs(
105 LogsCommands::View(_)
106 | LogsCommands::Search(_)
107 | LogsCommands::Stream(_)
108 | LogsCommands::Export(_)
109 | LogsCommands::Summary(_)
110 | LogsCommands::Show(_)
111 | LogsCommands::Trace(
112 logs::trace::TraceCommands::List(_) | logs::trace::TraceCommands::Show(_),
113 )
114 | LogsCommands::Governance(logs::governance::GovernanceCommands::Report(_))
115 | LogsCommands::Request(
116 logs::request::RequestCommands::List(_)
117 | logs::request::RequestCommands::Show(_)
118 | logs::request::RequestCommands::Stats(_),
119 )
120 | LogsCommands::Tools(logs::tools::ToolsCommands::List(_))
121 | LogsCommands::Audit(_),
122 )
123 | Self::Services(
124 ServicesCommands::Start { .. }
125 | ServicesCommands::Stop { .. }
126 | ServicesCommands::Restart { .. }
127 | ServicesCommands::Status { .. }
128 | ServicesCommands::Cleanup { .. }
129 | ServicesCommands::Serve { .. },
130 ) => DataImpact::Preserving,
131 }
132 }
133}