Skip to main content

systemprompt_cli/commands/core/content/
mod.rs

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