systemprompt_cli/commands/core/content/link/
show.rs1use crate::cli_settings::CliConfig;
2use crate::commands::core::content::types::LinkDetailOutput;
3use crate::shared::CommandOutput;
4use anyhow::{Result, anyhow};
5use clap::Args;
6use systemprompt_content::services::LinkGenerationService;
7use systemprompt_runtime::AppContext;
8
9const DEFAULT_BASE_URL: &str = "https://systemprompt.io";
10
11#[derive(Debug, Args)]
12pub struct ShowArgs {
13 #[arg(help = "Short code")]
14 pub short_code: String,
15}
16
17pub async fn execute(args: ShowArgs, _config: &CliConfig) -> Result<CommandOutput> {
18 let ctx = AppContext::new().await?;
19 let service = LinkGenerationService::new(ctx.db_pool())?;
20
21 let link = service
22 .get_link_by_short_code(&args.short_code)
23 .await?
24 .ok_or_else(|| anyhow!("Link not found: {}", args.short_code))?;
25
26 let full_url = link.get_full_url();
27 let short_url = format!("{}/r/{}", DEFAULT_BASE_URL, link.short_code);
28
29 let output = LinkDetailOutput {
30 id: link.id,
31 short_code: link.short_code,
32 target_url: link.target_url,
33 full_url: if full_url == short_url {
34 short_url
35 } else {
36 full_url
37 },
38 link_type: link.link_type,
39 campaign_id: link.campaign_id,
40 campaign_name: link.campaign_name,
41 source_content_id: link.source_content_id,
42 click_count: link.click_count.unwrap_or(0),
43 unique_click_count: link.unique_click_count.unwrap_or(0),
44 conversion_count: link.conversion_count.unwrap_or(0),
45 is_active: link.is_active.unwrap_or(true),
46 created_at: link.created_at,
47 };
48
49 Ok(CommandOutput::card_value("Link Details", &output))
50}