changed default behavior from unit to None
This commit is contained in:
parent
3445908ef9
commit
f527e7eb0a
1 changed files with 8 additions and 7 deletions
|
@ -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),
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue