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), - } + }); }); }