From 9dde4731f25adf49afe34d9e1b6c470867ff8d0e Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 4 Sep 2017 16:42:31 +0200 Subject: [PATCH] Rewrite retrieve() to use positional arg --- bin/core/imag-store/src/retrieve.rs | 26 ++++++++++++-------------- bin/core/imag-store/src/ui.rs | 3 +-- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/bin/core/imag-store/src/retrieve.rs b/bin/core/imag-store/src/retrieve.rs index 19c85b16..5c664f93 100644 --- a/bin/core/imag-store/src/retrieve.rs +++ b/bin/core/imag-store/src/retrieve.rs @@ -31,21 +31,19 @@ pub fn retrieve(rt: &Runtime) { rt.cli() .subcommand_matches("retrieve") .map(|scmd| { - scmd.value_of("id") - .map(|id| { - let path = PathBuf::from(id); - let path = try!(StoreId::new(Some(rt.store().path().clone()), path) - .map_err_trace_exit(1)); - debug!("path = {:?}", path); + // unwrap() is safe as arg is required + let id = scmd.value_of("id").unwrap(); + let path = PathBuf::from(id); + let store = Some(rt.store().path().clone()); + let path = try!(StoreId::new(store, path).map_err_trace_exit(1)); + debug!("path = {:?}", path); - rt.store() - // "id" must be present, enforced via clap spec - .retrieve(path) - .map(|e| print_entry(rt, scmd, e)) - .map_dbg_str("No entry") - .map_dbg(|e| format!("{:?}", e)) - .map_err_trace() - }) + rt.store() + .retrieve(path) + .map(|e| print_entry(rt, scmd, e)) + .map_dbg_str("No entry") + .map_dbg(|e| format!("{:?}", e)) + .map_err_trace() }); } diff --git a/bin/core/imag-store/src/ui.rs b/bin/core/imag-store/src/ui.rs index b8620c46..ff014f25 100644 --- a/bin/core/imag-store/src/ui.rs +++ b/bin/core/imag-store/src/ui.rs @@ -69,8 +69,7 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> { .about("Retrieve an entry from the store (implicitely creates the entry)") .version("0.1") .arg(Arg::with_name("id") - .long("id") - .short("i") + .index(1) .takes_value(true) .required(true) .help("Retreive by Store Path, where root (/) is the store itself"))