systemprompt_cli/commands/core/content/link/
delete.rs1use crate::commands::core::content::types::LinkDeleteOutput;
7use crate::context::CommandContext;
8use crate::interactive::require_confirmation;
9use crate::shared::CommandOutput;
10use anyhow::{Result, anyhow};
11use clap::Args;
12use systemprompt_content::services::LinkGenerationService;
13use systemprompt_identifiers::LinkId;
14use systemprompt_logging::CliService;
15
16#[derive(Debug, Args)]
17pub struct DeleteArgs {
18 #[arg(help = "Link ID")]
19 pub link_id: String,
20
21 #[arg(short = 'y', long, help = "Skip confirmation")]
22 pub yes: bool,
23}
24
25pub async fn execute(args: DeleteArgs, ctx: &CommandContext) -> Result<CommandOutput> {
26 let link_id = LinkId::new(args.link_id.clone());
27
28 if ctx.cli.is_interactive() && !args.yes {
29 CliService::warning(&format!(
30 "This will permanently delete link: {}",
31 args.link_id
32 ));
33 }
34
35 require_confirmation(
36 ctx.prompter(),
37 "Are you sure you want to continue?",
38 args.yes,
39 &ctx.cli,
40 )?;
41
42 let pool = ctx.db_pool().await?;
43 let service = LinkGenerationService::new(&pool)?;
44
45 service
46 .get_link_by_id(&link_id)
47 .await?
48 .ok_or_else(|| anyhow!("Link not found: {}", args.link_id))?;
49
50 let deleted = service.delete_link(&link_id).await?;
51
52 let output = LinkDeleteOutput { deleted, link_id };
53
54 Ok(CommandOutput::card_value("Link Deleted", &output))
55}