diff options
-rw-r--r-- | bin/core/imag-ref/Cargo.toml | 8 | ||||
-rw-r--r-- | bin/core/imag-ref/src/main.rs | 19 |
2 files changed, 25 insertions, 2 deletions
diff --git a/bin/core/imag-ref/Cargo.toml b/bin/core/imag-ref/Cargo.toml index 42f4665a..bf3cb6c0 100644 --- a/bin/core/imag-ref/Cargo.toml +++ b/bin/core/imag-ref/Cargo.toml @@ -22,7 +22,8 @@ is-it-maintained-open-issues = { repository = "matthiasbeyer/imag" } maintenance = { status = "actively-developed" } [dependencies] -log = "0.4.0" +log = "0.4.0" +failure = "0.1" libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" } @@ -36,3 +37,8 @@ version = "^2.29" default-features = false features = ["color", "suggestions", "wrap_help"] +[dependencies.toml-query] +version = "0.8" +default-features = false +features = ["typed"] + diff --git a/bin/core/imag-ref/src/main.rs b/bin/core/imag-ref/src/main.rs index 332e9477..63edf367 100644 --- a/bin/core/imag-ref/src/main.rs +++ b/bin/core/imag-ref/src/main.rs @@ -35,7 +35,9 @@ )] #[macro_use] extern crate log; +#[macro_use] extern crate failure; extern crate clap; +extern crate toml_query; extern crate libimagstore; #[macro_use] extern crate libimagrt; @@ -50,6 +52,8 @@ use ui::build_ui; use std::process::exit; use std::io::Write; +use failure::Fallible as Result; + use libimagerror::trace::MapErrTrace; use libimagerror::exit::ExitUnwrap; use libimagrt::setup::generate_runtime_setup; @@ -58,6 +62,7 @@ use libimagentryref::reference::Ref; use libimagentryref::reference::MutRef; use libimagentryref::reference::RefFassade; use libimagentryref::hasher::default::DefaultHasher; +use libimagentryref::reference::Config as RefConfig; fn main() { let version = make_imag_version!(); @@ -87,6 +92,7 @@ fn main() { fn deref(rt: &Runtime) { let cmd = rt.cli().subcommand_matches("deref").unwrap(); let ids = rt.ids::<::ui::PathProvider>().map_err_trace_exit_unwrap(); + let cfg = get_ref_config(&rt).map_err_trace_exit_unwrap(); let out = rt.stdout(); let mut outlock = out.lock(); @@ -96,7 +102,7 @@ fn deref(rt: &Runtime) { Some(entry) => { entry .as_ref_with_hasher::<DefaultHasher>() - .get_path() + .get_path(&cfg) .map_err_trace_exit_unwrap() .to_str() .ok_or_else(|| { @@ -157,3 +163,14 @@ fn create(rt: &Runtime) { unimplemented!() } +fn get_ref_config(rt: &Runtime) -> Result<RefConfig> { + use toml_query::read::TomlValueReadExt; + + let setting_name = "ref.basepathes"; + + rt.config() + .ok_or_else(|| format_err!("No configuration, cannot find collection name for ref collection"))? + .read_deserialized::<RefConfig>(setting_name)? + .ok_or_else(|| format_err!("Setting missing: {}", setting_name)) +} + |