Skip to main content

systemprompt_cli/commands/core/content/files/
mod.rs

1//! `core content files` command group: associate stored files with content.
2//!
3//! Dispatches the [`ContentFilesCommands`] subcommands (link, unlink, list,
4//! featured) that manage the content-to-file relationships and the featured
5//! image for a content item.
6//!
7//! Copyright (c) systemprompt.io — Business Source License 1.1.
8//! See <https://systemprompt.io> for licensing details.
9
10pub mod featured;
11pub mod link;
12pub mod list;
13pub mod unlink;
14
15use anyhow::{Context, Result};
16use clap::Subcommand;
17
18use crate::CliConfig;
19use crate::interactive::Prompter;
20use crate::shared::render_result;
21
22#[derive(Debug, Subcommand)]
23pub enum ContentFilesCommands {
24    #[command(about = "Link a file to content with a specific role")]
25    Link(link::LinkArgs),
26
27    #[command(about = "Unlink a file from content")]
28    Unlink(unlink::UnlinkArgs),
29
30    #[command(about = "List files attached to content")]
31    List(list::ListArgs),
32
33    #[command(about = "Get or set the featured image for content")]
34    Featured(featured::FeaturedArgs),
35}
36
37pub async fn execute(
38    cmd: ContentFilesCommands,
39    prompter: &dyn Prompter,
40    config: &CliConfig,
41) -> Result<()> {
42    match cmd {
43        ContentFilesCommands::Link(args) => {
44            let result = link::execute(args, config)
45                .await
46                .context("Failed to link file to content")?;
47            render_result(&result, config);
48            Ok(())
49        },
50        ContentFilesCommands::Unlink(args) => {
51            let result = unlink::execute(args, prompter, config)
52                .await
53                .context("Failed to unlink file from content")?;
54            render_result(&result, config);
55            Ok(())
56        },
57        ContentFilesCommands::List(args) => {
58            let result = list::execute(args, config)
59                .await
60                .context("Failed to list content files")?;
61            render_result(&result, config);
62            Ok(())
63        },
64        ContentFilesCommands::Featured(args) => {
65            let result = featured::execute(args, config)
66                .await
67                .context("Failed to get/set featured image")?;
68            render_result(&result, config);
69            Ok(())
70        },
71    }
72}