diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2017-09-04 16:46:32 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2017-09-05 17:36:32 +0200 |
commit | 9e9c04e5f340670c896d77d3fc32713269c4ae09 (patch) | |
tree | 1f53814ba64a705aff4f919e200aa1d6d12dfda4 /bin/core/imag-store/src | |
parent | 381223efd929c1d2386efdeaac1eff65a8066c29 (diff) |
Rewrite update() to use positional arg
Diffstat (limited to 'bin/core/imag-store/src')
-rw-r--r-- | bin/core/imag-store/src/update.rs | 46 |
1 files changed, 19 insertions, 27 deletions
diff --git a/bin/core/imag-store/src/update.rs b/bin/core/imag-store/src/update.rs index d0f245d5..9fccadaa 100644 --- a/bin/core/imag-store/src/update.rs +++ b/bin/core/imag-store/src/update.rs @@ -27,33 +27,25 @@ use libimagstore::storeid::StoreId; use util::build_toml_header; pub fn update(rt: &Runtime) { - rt.cli() - .subcommand_matches("update") - .map(|scmd| { - scmd.value_of("id") - .map(|id| { - let path = PathBuf::from(id); - let path = match StoreId::new(Some(rt.store().path().clone()), path) { - Err(e) => trace_error_exit(&e, 1), - Ok(p) => p, - }; - - rt.store() - .retrieve(path) - .map(|mut locked_e| { - let e = locked_e.deref_mut(); - - scmd.value_of("content") - .map(|new_content| { - *e.get_content_mut() = String::from(new_content); - debug!("New content set"); - }); - - *e.get_header_mut() = build_toml_header(scmd, e.get_header().clone()); - debug!("New header set"); - }) - }) + let scmd = rt.cli().subcommand_matches("update").unwrap(); + let id = scmd.value_of("id").unwrap(); // Safe by clap + let path = PathBuf::from(id); + let store = Some(rt.store().path().clone()); + let path = StoreId::new(store, path).unwrap_or_else(|e| trace_error_exit(&e, 1)); + + let _ = rt.store() + .retrieve(path) + .map(|mut locked_e| { + let e = locked_e.deref_mut(); + + scmd.value_of("content") + .map(|new_content| { + *e.get_content_mut() = String::from(new_content); + debug!("New content set"); + }); + + *e.get_header_mut() = build_toml_header(scmd, e.get_header().clone()); + debug!("New header set"); }); - } |