Skip to main content

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

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