changed default behavior from unit to None

This commit is contained in:
Kai Sickeler 2016-07-18 22:05:18 +02:00
parent 3445908ef9
commit f527e7eb0a

View file

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