From f527e7eb0aed28e4ce02262e3158b4b228071d9a Mon Sep 17 00:00:00 2001 From: Kai Sickeler Date: Mon, 18 Jul 2016 22:05:18 +0200 Subject: [PATCH] changed default behavior from unit to None --- imag-counter/src/create.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/imag-counter/src/create.rs b/imag-counter/src/create.rs index 04ec3bb7..9b455df5 100644 --- a/imag-counter/src/create.rs +++ b/imag-counter/src/create.rs @@ -3,6 +3,7 @@ use std::str::FromStr; use libimagrt::runtime::Runtime; use libimagerror::trace::trace_error_exit; use libimagcounter::counter::Counter; +use libimagcounter::counter::CounterUnit; pub fn create(rt: &Runtime) { rt.cli() @@ -15,16 +16,16 @@ pub fn create(rt: &Runtime) { .value_of("initval") .and_then(|i| FromStr::from_str(i).ok()) .unwrap_or(0); + let unit = scmd .value_of("unit") - .unwrap_or("unit"); + .map(CounterUnit::new); - match Counter::new(rt.store(), String::from(name), init) { - Err(e) => { - warn!("Could not create Counter '{}' with initial value '{} {}'", name, init, unit); + Counter::new(rt.store(), String::from(name), init) + .and_then(|c| c.with_unit(unit)) + .unwrap_or_else(|e| { + warn!("Could not create Counter '{}' with initial value '{}'", name, init); trace_error_exit(&e, 1); - }, - Ok(_) => info!("Created Counter '{}' with initial value '{} {}'", name, init, unit), - } + }); }); }