diff --git a/imag-tag/src/main.rs b/imag-tag/src/main.rs index 87b9919d..52c39168 100644 --- a/imag-tag/src/main.rs +++ b/imag-tag/src/main.rs @@ -13,12 +13,11 @@ use std::process::exit; use libimagrt::runtime::Runtime; use libimagtag::tagable::Tagable; +use libimagstore::storeid::build_entry_path; mod ui; -mod util; use ui::build_ui; -use util::build_entry_path; use libimagutil::trace::trace_error; @@ -68,8 +67,17 @@ fn main() { } fn alter(rt: &Runtime, id: &str, add: Option<&str>, rem: Option<&str>, set: Option<&str>) { - let path = build_entry_path(rt, id); + let path = { + match build_entry_path(rt.store(), id) { + Err(e) => { + trace_error(&e); + exit(1); + }, + Ok(s) => s, + } + }; debug!("path = {:?}", path); + rt.store() // "id" must be present, enforced via clap spec .retrieve(path) @@ -110,7 +118,15 @@ fn alter(rt: &Runtime, id: &str, add: Option<&str>, rem: Option<&str>, set: Opti } fn list(id: &str, rt: &Runtime) { - let path = build_entry_path(rt, id); + let path = { + match build_entry_path(rt.store(), id) { + Err(e) => { + trace_error(&e); + exit(1); + }, + Ok(s) => s, + } + }; debug!("path = {:?}", path); let entry = rt.store().retrieve(path.clone()); diff --git a/imag-tag/src/util.rs b/imag-tag/src/util.rs deleted file mode 100644 index b33e045d..00000000 --- a/imag-tag/src/util.rs +++ /dev/null @@ -1,36 +0,0 @@ -use std::path::PathBuf; - -use semver::Version; - -use libimagrt::runtime::Runtime; - -pub fn build_entry_path(rt: &Runtime, path_elem: &str) -> PathBuf { - debug!("Checking path element for version"); - { - let contains_version = { - path_elem.split("~") - .last() - .map(|version| Version::parse(version).is_ok()) - .unwrap_or(false) - }; - - if !contains_version { - debug!("Version cannot be parsed inside {:?}", path_elem); - warn!("Path does not contain version. Will panic now!"); - panic!("No version in path"); - } - } - debug!("Version checking succeeded"); - - debug!("Building path from {:?}", path_elem); - let mut path = rt.store().path().clone(); - - if path_elem.chars().next() == Some('/') { - path.push(&path_elem[1..path_elem.len()]); - } else { - path.push(path_elem); - } - - path -} -