Skip to main content

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

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