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