systemprompt_cli/commands/core/files/
mod.rs1pub mod types;
2
3mod config;
4mod delete;
5mod list;
6mod search;
7mod show;
8mod stats;
9pub mod upload;
10mod validate;
11
12pub mod ai;
13
14use anyhow::{bail, Context, Result};
15use clap::Subcommand;
16use systemprompt_runtime::DatabaseContext;
17
18use crate::shared::render_result;
19use crate::CliConfig;
20
21#[derive(Debug, Subcommand)]
22pub enum FilesCommands {
23 #[command(about = "List files with pagination and filtering")]
24 List(list::ListArgs),
25
26 #[command(about = "Show detailed file information")]
27 Show(show::ShowArgs),
28
29 #[command(about = "Upload a file from the local filesystem")]
30 Upload(upload::UploadArgs),
31
32 #[command(about = "Delete a file")]
33 Delete(delete::DeleteArgs),
34
35 #[command(about = "Validate a file before upload")]
36 Validate(validate::ValidateArgs),
37
38 #[command(about = "Show file upload configuration")]
39 Config(config::ConfigArgs),
40
41 #[command(about = "Search files by path pattern")]
42 Search(search::SearchArgs),
43
44 #[command(about = "Show file storage statistics")]
45 Stats(stats::StatsArgs),
46
47 #[command(subcommand, about = "AI-generated images operations")]
48 Ai(ai::AiCommands),
49}
50
51pub async fn execute(cmd: FilesCommands, config: &CliConfig) -> Result<()> {
52 execute_with_config(cmd, config).await
53}
54
55pub async fn execute_with_config(cmd: FilesCommands, config: &CliConfig) -> Result<()> {
56 match cmd {
57 FilesCommands::List(args) => {
58 let result = list::execute(args, config)
59 .await
60 .context("Failed to list files")?;
61 render_result(&result);
62 Ok(())
63 },
64 FilesCommands::Show(args) => {
65 let result = show::execute(args, config)
66 .await
67 .context("Failed to show file")?;
68 render_result(&result);
69 Ok(())
70 },
71 FilesCommands::Upload(args) => {
72 let result = upload::execute(args, config)
73 .await
74 .context("Failed to upload file")?;
75 render_result(&result);
76 Ok(())
77 },
78 FilesCommands::Delete(args) => {
79 let result = delete::execute(args, config)
80 .await
81 .context("Failed to delete file")?;
82 render_result(&result);
83 Ok(())
84 },
85 FilesCommands::Validate(args) => {
86 let result = validate::execute(&args, config).context("Failed to validate file")?;
87 render_result(&result);
88 Ok(())
89 },
90 FilesCommands::Config(args) => {
91 let result = config::execute(args, config).context("Failed to get file config")?;
92 render_result(&result);
93 Ok(())
94 },
95 FilesCommands::Search(args) => {
96 let result = search::execute(args, config)
97 .await
98 .context("Failed to search files")?;
99 render_result(&result);
100 Ok(())
101 },
102 FilesCommands::Stats(args) => {
103 let result = stats::execute(args, config)
104 .await
105 .context("Failed to get file stats")?;
106 render_result(&result);
107 Ok(())
108 },
109 FilesCommands::Ai(cmd) => ai::execute(cmd, config).await,
110 }
111}
112
113pub async fn execute_with_db(
114 cmd: FilesCommands,
115 db_ctx: &DatabaseContext,
116 config: &CliConfig,
117) -> Result<()> {
118 match cmd {
119 FilesCommands::List(args) => {
120 let result = list::execute_with_pool(args, db_ctx.db_pool(), config)
121 .await
122 .context("Failed to list files")?;
123 render_result(&result);
124 Ok(())
125 },
126 FilesCommands::Show(args) => {
127 let result = show::execute_with_pool(args, db_ctx.db_pool(), config)
128 .await
129 .context("Failed to show file")?;
130 render_result(&result);
131 Ok(())
132 },
133 FilesCommands::Search(args) => {
134 let result = search::execute_with_pool(args, db_ctx.db_pool(), config)
135 .await
136 .context("Failed to search files")?;
137 render_result(&result);
138 Ok(())
139 },
140 FilesCommands::Stats(args) => {
141 let result = stats::execute_with_pool(args, db_ctx.db_pool(), config)
142 .await
143 .context("Failed to get file stats")?;
144 render_result(&result);
145 Ok(())
146 },
147 FilesCommands::Upload(_)
148 | FilesCommands::Delete(_)
149 | FilesCommands::Validate(_)
150 | FilesCommands::Config(_)
151 | FilesCommands::Ai(_) => {
152 bail!("This files command requires full profile context")
153 },
154 }
155}