From 10409703d87938d38e322302badca977d1cae9de Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 28 May 2016 21:19:29 +0200 Subject: [PATCH] Rewrite UI to use Store::get() which does not implicitely create entries --- imag-tag/src/main.rs | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/imag-tag/src/main.rs b/imag-tag/src/main.rs index fdac5ac9..efda69a8 100644 --- a/imag-tag/src/main.rs +++ b/imag-tag/src/main.rs @@ -62,10 +62,8 @@ fn alter(rt: &Runtime, id: &str, add: Option>, rem: Option>) { }; debug!("path = {:?}", path); - rt.store() - // "id" must be present, enforced via clap spec - .retrieve(path) - .map(|mut e| { + match rt.store().get(path) { + Ok(Some(mut e)) => { add.map(|tags| { for tag in tags { debug!("Adding tag '{:?}'", tag); @@ -83,12 +81,17 @@ fn alter(rt: &Runtime, id: &str, add: Option>, rem: Option>) { } } }); // it is okay to ignore a None here - }) - .map_err(|e| { + }, + + Ok(None) => { + info!("No entry found."); + }, + + Err(e) => { info!("No entry."); trace_error(&e); - }) - .ok(); + }, + } } fn list(id: &str, rt: &Runtime) { @@ -103,14 +106,20 @@ fn list(id: &str, rt: &Runtime) { }; debug!("path = {:?}", path); - let entry = rt.store().retrieve(path.clone()); - if entry.is_err() { - debug!("Could not retrieve '{:?}' => {:?}", id, path); - warn!("Could not retrieve entry '{}'", id); - trace_error(&entry.unwrap_err()); - exit(1); - } - let entry = entry.unwrap(); + let entry = match rt.store().get(path.clone()) { + Ok(Some(e)) => e, + Ok(None) => { + info!("No entry found."); + exit(1); + }, + + Err(e) => { + debug!("Could not get '{:?}' => {:?}", id, path); + warn!("Could not get entry '{}'", id); + trace_error(&e); + exit(1); + }, + }; let scmd = rt.cli().subcommand_matches("list").unwrap(); // safe, we checked in main()