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::CommandResult;
5use anyhow::{anyhow, Result};
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(
22 args: DeleteArgs,
23 config: &CliConfig,
24) -> Result<CommandResult<LinkDeleteOutput>> {
25 let link_id = LinkId::new(args.link_id.clone());
26
27 if config.is_interactive() && !args.yes {
28 CliService::warning(&format!(
29 "This will permanently delete link: {}",
30 args.link_id
31 ));
32 }
33
34 require_confirmation("Are you sure you want to continue?", args.yes, config)?;
35
36 let ctx = AppContext::new().await?;
37 let service = LinkGenerationService::new(ctx.db_pool())?;
38
39 service
40 .get_link_by_id(&link_id)
41 .await?
42 .ok_or_else(|| anyhow!("Link not found: {}", args.link_id))?;
43
44 let deleted = service.delete_link(&link_id).await?;
45
46 let output = LinkDeleteOutput { deleted, link_id };
47
48 Ok(CommandResult::card(output).with_title("Link Deleted"))
49}