refactor: remove mode_get function
This commit is contained in:
committed by
Andrew Phillips (aider)
parent
60515c628a
commit
bb04d7ca0b
40
src/main.rs
40
src/main.rs
@@ -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(
|
fn mode_diff(
|
||||||
cmd: &mut clap::Command,
|
cmd: &mut clap::Command,
|
||||||
_args: Args, // Mark as unused if not needed directly
|
_args: Args, // Mark as unused if not needed directly
|
||||||
|
|||||||
Reference in New Issue
Block a user