Files
keep/src/modes/delete.rs
Andrew Phillips 0fe61de89e fix: remove unused anyhow import
Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
2025-08-25 17:49:10 -03:00

51 lines
1.3 KiB
Rust

use anyhow::Result;
use std::path::PathBuf;
use crate::config;
use crate::services::error::CoreError;
use crate::services::item_service::ItemService;
use clap::error::ErrorKind;
use clap::Command;
use log::warn;
use rusqlite::Connection;
pub fn mode_delete(
cmd: &mut Command,
_settings: &config::Settings,
_config: &config::Settings,
ids: &mut Vec<i64>,
tags: &mut Vec<String>,
conn: &mut Connection,
data_path: PathBuf,
) -> Result<()> {
if ids.is_empty() {
cmd.error(
ErrorKind::InvalidValue,
"No ID given, you must supply atleast one ID when using --delete",
)
.exit();
} else if !tags.is_empty() {
cmd.error(
ErrorKind::InvalidValue,
"Tags given but not supported, you must supply atleast one ID when using --delete",
)
.exit();
}
let item_service = ItemService::new(data_path);
for item_id in ids.iter() {
match item_service.delete_item(conn, *item_id) {
Ok(_) => {}
Err(e) => match e {
CoreError::ItemNotFound(_) => {
warn!("Unable to find item {item_id} in database");
}
_ => return Err(anyhow::Error::from(e).context(format!("Failed to delete item {}", item_id))),
},
}
}
Ok(())
}