diff --git a/bin/core/imag-ref/src/main.rs b/bin/core/imag-ref/src/main.rs index a9500beb..5aaec5ed 100644 --- a/bin/core/imag-ref/src/main.rs +++ b/bin/core/imag-ref/src/main.rs @@ -86,27 +86,32 @@ 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, "imag-ref").map_err_trace_exit_unwrap(); - let out = rt.stdout(); + let cmd = rt.cli().subcommand_matches("deref").unwrap(); + let basepath = cmd.value_of("override-basepath"); + let ids = rt.ids::<::ui::PathProvider>().map_err_trace_exit_unwrap(); + let cfg = get_ref_config(&rt, "imag-ref").map_err_trace_exit_unwrap(); + let out = rt.stdout(); let mut outlock = out.lock(); ids.into_iter() .for_each(|id| { match rt.store().get(id.clone()).map_err_trace_exit_unwrap() { Some(entry) => { - entry - .as_ref_with_hasher::() - .get_path(&cfg) - .map_err_trace_exit_unwrap() - .to_str() - .ok_or_else(|| { - error!("Could not transform path into string!"); - exit(1) - }) - .map(|s| writeln!(outlock, "{}", s)) - .ok(); // safe here because we exited already in the error case + let r_entry = entry.as_ref_with_hasher::(); + + if let Some(alternative_basepath) = basepath { + r_entry.get_path_with_basepath_setting(&cfg, alternative_basepath) + } else { + r_entry.get_path(&cfg) + } + .map_err_trace_exit_unwrap() + .to_str() + .ok_or_else(|| { + error!("Could not transform path into string!"); + exit(1) + }) + .map(|s| writeln!(outlock, "{}", s)) + .ok(); // safe here because we exited already in the error case let _ = rt.report_touched(&id).unwrap_or_exit(); }, diff --git a/bin/core/imag-ref/src/ui.rs b/bin/core/imag-ref/src/ui.rs index c14eafe2..1a264ea5 100644 --- a/bin/core/imag-ref/src/ui.rs +++ b/bin/core/imag-ref/src/ui.rs @@ -45,6 +45,14 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> { .required(false) .multiple(false) .help("Ignore store entries which are not refs and do not print error message")) + + .arg(Arg::with_name("override-basepath") + .long("basepath-setting") + .short("B") + .takes_value(true) + .required(false) + .multiple(false) + .help("Override the basepath key to look up in the configuration")) ) .subcommand(SubCommand::with_name("remove")