refactor: remove mode_get function

This commit is contained in:
Andrew Phillips
2025-05-10 08:31:53 -03:00
committed by Andrew Phillips (aider)
parent 60515c628a
commit bb04d7ca0b

View File

@@ -445,46 +445,6 @@ fn mode_save(cmd: &mut Command, args: Args, ids: &mut Vec<i64>, tags: &mut Vec<S
}
pub fn mode_get(cmd: &mut Command, args: Args, ids: &mut Vec<i64>, tags: &mut Vec<String>, conn: &mut Connection, data_path: PathBuf) -> Result<()> {
if ! ids.is_empty() && ! tags.is_empty() {
cmd.error(ErrorKind::InvalidValue, "Both ID and tags given, you must supply exactly one ID or atleast one tag when using --get").exit();
} else if ids.len() > 1 {
cmd.error(ErrorKind::InvalidValue, "More than one ID given, you must supply exactly one ID or atleast one tag when using --get").exit();
}
let mut meta: HashMap<String, String> = HashMap::new();
for item in args.item.meta.iter() {
let item = item.clone();
meta.insert(item.key, item.value);
}
let item_maybe = match tags.is_empty() && meta.is_empty() {
true => match ids.iter().next() {
Some(item_id) => db::get_item(conn, *item_id)?,
None => db::get_item_last(conn)?
},
false => db::get_item_matching(conn, tags, &meta)?
};
if let Some(item) = item_maybe {
debug!("MAIN: Found item {:?}", item);
let mut item_path = data_path.clone();
item_path.push(item.id.unwrap().to_string());
let compression_type = CompressionType::from_str(&item.compression)?;
debug!("MAIN: Item has compression type {:?}", compression_type.clone());
let compression_engine = get_engine(compression_type).expect("Unable to get compression engine");
compression_engine.cat(item_path.clone())?;
Ok(())
} else {
Err(anyhow!("Unable to find matching item in database"))
}
}
fn mode_diff(
cmd: &mut clap::Command,
_args: Args, // Mark as unused if not needed directly