diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-05-28 21:19:29 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2016-05-28 21:19:29 +0200 |
commit | 10409703d87938d38e322302badca977d1cae9de (patch) | |
tree | 28ba99dde1ae25d8079b1e6a86facafeb6874ea9 /imag-tag | |
parent | 59152e6a52ce742142c3fbee8386a517402c56a2 (diff) |
Rewrite UI to use Store::get() which does not implicitely create entries
Diffstat (limited to 'imag-tag')
-rw-r--r-- | imag-tag/src/main.rs | 41 |
1 files 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<Vec<Tag>>, rem: Option<Vec<Tag>>) { }; 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<Vec<Tag>>, rem: Option<Vec<Tag>>) { } } }); // 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() |