systemprompt_cli/commands/core/content/
mod.rs1pub mod analytics;
2pub mod delete;
3pub mod delete_source;
4mod edit;
5pub mod files;
6pub mod link;
7pub mod list;
8pub mod popular;
9pub mod search;
10pub mod show;
11pub mod status;
12pub mod types;
13pub mod verify;
14
15use crate::cli_settings::{get_global_config, CliConfig};
16use crate::shared::render_result;
17use anyhow::{bail, Context, Result};
18use clap::Subcommand;
19use systemprompt_runtime::DatabaseContext;
20
21#[derive(Debug, Subcommand)]
22pub enum ContentCommands {
23 #[command(about = "List content with pagination")]
24 List(list::ListArgs),
25
26 #[command(about = "Show content details")]
27 Show(show::ShowArgs),
28
29 #[command(about = "Search content")]
30 Search(search::SearchArgs),
31
32 #[command(about = "Edit content fields")]
33 Edit(edit::EditArgs),
34
35 #[command(about = "Delete content by ID")]
36 Delete(delete::DeleteArgs),
37
38 #[command(name = "delete-source", about = "Delete all content from a source")]
39 DeleteSource(delete_source::DeleteSourceArgs),
40
41 #[command(about = "Get popular content")]
42 Popular(popular::PopularArgs),
43
44 #[command(about = "Verify content is published and accessible")]
45 Verify(verify::VerifyArgs),
46
47 #[command(about = "Show content health status for a source")]
48 Status(status::StatusArgs),
49
50 #[command(subcommand, about = "Link generation and management")]
51 Link(link::LinkCommands),
52
53 #[command(subcommand, about = "Content analytics")]
54 Analytics(analytics::AnalyticsCommands),
55
56 #[command(subcommand, about = "Content-file operations (link, unlink, featured)")]
57 Files(files::ContentFilesCommands),
58}
59
60pub async fn execute(command: ContentCommands) -> Result<()> {
61 let config = get_global_config();
62 execute_with_config(command, &config).await
63}
64
65pub async fn execute_with_config(command: ContentCommands, config: &CliConfig) -> Result<()> {
66 match command {
67 ContentCommands::List(args) => {
68 let result = list::execute(args, config)
69 .await
70 .context("Failed to list content")?;
71 render_result(&result);
72 },
73 ContentCommands::Show(args) => {
74 let result = show::execute(args, config)
75 .await
76 .context("Failed to show content")?;
77 render_result(&result);
78 },
79 ContentCommands::Search(args) => {
80 let result = search::execute(args, config)
81 .await
82 .context("Failed to search content")?;
83 render_result(&result);
84 },
85 ContentCommands::Edit(args) => {
86 let result = edit::execute(args, config)
87 .await
88 .context("Failed to edit content")?;
89 render_result(&result);
90 },
91 ContentCommands::Delete(args) => {
92 let result = delete::execute(args, config)
93 .await
94 .context("Failed to delete content")?;
95 render_result(&result);
96 },
97 ContentCommands::DeleteSource(args) => {
98 let result = delete_source::execute(args, config)
99 .await
100 .context("Failed to delete source content")?;
101 render_result(&result);
102 },
103 ContentCommands::Popular(args) => {
104 let result = popular::execute(args, config)
105 .await
106 .context("Failed to get popular content")?;
107 render_result(&result);
108 },
109 ContentCommands::Verify(args) => {
110 let result = verify::execute(args, config)
111 .await
112 .context("Failed to verify content")?;
113 render_result(&result);
114 },
115 ContentCommands::Status(args) => {
116 let result = status::execute(args, config)
117 .await
118 .context("Failed to get content status")?;
119 render_result(&result);
120 },
121 ContentCommands::Link(cmd) => {
122 link::execute(cmd, config).await?;
123 },
124 ContentCommands::Analytics(cmd) => {
125 analytics::execute(cmd, config).await?;
126 },
127 ContentCommands::Files(cmd) => {
128 files::execute(cmd, config).await?;
129 },
130 }
131 Ok(())
132}
133
134pub async fn execute_with_db(
135 command: ContentCommands,
136 db_ctx: &DatabaseContext,
137 config: &CliConfig,
138) -> Result<()> {
139 match command {
140 ContentCommands::List(args) => {
141 let result = list::execute_with_pool(args, db_ctx.db_pool(), config)
142 .await
143 .context("Failed to list content")?;
144 render_result(&result);
145 },
146 ContentCommands::Show(args) => {
147 let result = show::execute_with_pool(args, db_ctx.db_pool(), config)
148 .await
149 .context("Failed to show content")?;
150 render_result(&result);
151 },
152 ContentCommands::Search(args) => {
153 let result = search::execute_with_pool(args, db_ctx.db_pool(), config)
154 .await
155 .context("Failed to search content")?;
156 render_result(&result);
157 },
158 ContentCommands::Popular(args) => {
159 let result = popular::execute_with_pool(args, db_ctx.db_pool(), config)
160 .await
161 .context("Failed to get popular content")?;
162 render_result(&result);
163 },
164 ContentCommands::Status(args) => {
165 let result = status::execute_with_pool(args, db_ctx.db_pool(), config)
166 .await
167 .context("Failed to get content status")?;
168 render_result(&result);
169 },
170 ContentCommands::Analytics(cmd) => {
171 analytics::execute_with_pool(cmd, db_ctx.db_pool(), config).await?;
172 },
173 ContentCommands::Edit(_)
174 | ContentCommands::Delete(_)
175 | ContentCommands::DeleteSource(_)
176 | ContentCommands::Verify(_)
177 | ContentCommands::Link(_)
178 | ContentCommands::Files(_) => {
179 bail!("This content command requires full profile context")
180 },
181 }
182 Ok(())
183}