Skip to main content

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

1//! `core content link` command group: trackable campaign links.
2//!
3//! Dispatches the [`LinkCommands`] subcommands (generate, show, list,
4//! performance, delete) for creating short codes and reading their click
5//! metrics.
6//!
7//! Copyright (c) systemprompt.io — Business Source License 1.1.
8//! See <https://systemprompt.io> for licensing details.
9
10pub mod delete;
11pub mod generate;
12pub mod list;
13pub mod performance;
14pub mod show;
15
16use crate::context::CommandContext;
17use crate::shared::render_result;
18use anyhow::{Context, Result};
19use clap::Subcommand;
20
21#[derive(Debug, Subcommand)]
22pub enum LinkCommands {
23    #[command(about = "Generate a trackable campaign link")]
24    Generate(generate::GenerateArgs),
25
26    #[command(about = "Show link details by short code")]
27    Show(show::ShowArgs),
28
29    #[command(about = "List links by campaign or content")]
30    List(list::ListArgs),
31
32    #[command(about = "Show link performance metrics")]
33    Performance(performance::PerformanceArgs),
34
35    #[command(about = "Delete a link")]
36    Delete(delete::DeleteArgs),
37}
38
39pub async fn execute(command: LinkCommands, ctx: &CommandContext) -> Result<()> {
40    match command {
41        LinkCommands::Generate(args) => {
42            let result = generate::execute(args, ctx)
43                .await
44                .context("Failed to generate link")?;
45            render_result(&result, &ctx.cli);
46        },
47        LinkCommands::Show(args) => {
48            let result = show::execute(args, ctx)
49                .await
50                .context("Failed to show link")?;
51            render_result(&result, &ctx.cli);
52        },
53        LinkCommands::List(args) => {
54            let result = list::execute(args, ctx)
55                .await
56                .context("Failed to list links")?;
57            render_result(&result, &ctx.cli);
58        },
59        LinkCommands::Performance(args) => {
60            let result = performance::execute(args, ctx)
61                .await
62                .context("Failed to get link performance")?;
63            render_result(&result, &ctx.cli);
64        },
65        LinkCommands::Delete(args) => {
66            let result = delete::execute(args, ctx)
67                .await
68                .context("Failed to delete link")?;
69            render_result(&result, &ctx.cli);
70        },
71    }
72    Ok(())
73}