From 10e7a82a453fde1b1caea298950e4aebfec68ee6 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 8 Feb 2018 15:20:38 +0100 Subject: [PATCH] Refactor imag-diary --- bin/domain/imag-diary/src/create.rs | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/bin/domain/imag-diary/src/create.rs b/bin/domain/imag-diary/src/create.rs index b1f6f976..e86ada02 100644 --- a/bin/domain/imag-diary/src/create.rs +++ b/bin/domain/imag-diary/src/create.rs @@ -58,7 +58,7 @@ fn create_entry<'a>(diary: &'a Store, diaryname: &str, rt: &Runtime) -> FileLock let create = rt.cli().subcommand_matches("create").unwrap(); - let create_timed = create.value_of("timed") + create.value_of("timed") .map(|t| parse_timed_string(t, diaryname).map_err_trace_exit_unwrap(1)) .map(Some) .unwrap_or_else(|| { @@ -70,24 +70,20 @@ fn create_entry<'a>(diary: &'a Store, diaryname: &str, rt: &Runtime) -> FileLock None } } - }); - - let entry = match create_timed { - Some(timed) => { + }) + .map(|timed| { let id = create_id_from_clispec(&create, &diaryname, timed); diary.retrieve(id).chain_err(|| DEK::StoreReadError) - }, - - None => { + }) + .unwrap_or_else(|| { debug!("Creating non-timed entry"); diary.new_entry_today(diaryname) - } - }; - - let e = entry.map_err_trace_exit_unwrap(1); - - debug!("Created: {}", e.get_location()); - e + }) + .map(|e| { + debug!("Created: {}", e.get_location()); + e + }) + .map_err_trace_exit_unwrap(1) }