Implement list() for imag-counter

This commit is contained in:
Matthias Beyer 2016-03-13 16:50:10 +01:00
parent 78feb53aa8
commit 2e340acbb7

View file

@ -1,4 +1,7 @@
use libimagrt::runtime::Runtime; use libimagrt::runtime::Runtime;
use libimagutil::trace::trace_error;
use libimagcounter::counter::Counter;
use libimagcounter::result::Result;
pub fn list(rt: &Runtime) { pub fn list(rt: &Runtime) {
rt.cli() rt.cli()
@ -6,5 +9,27 @@ pub fn list(rt: &Runtime) {
.map(|scmd| { .map(|scmd| {
debug!("Found 'list' subcommand..."); debug!("Found 'list' subcommand...");
Counter::all_counters(rt.store()).map(|iterator| {
for counter in iterator {
counter.map(|c| {
let name = c.name();
let value = c.value();
if name.is_err() {
trace_error(&name.err().unwrap());
} else {
if value.is_err() {
trace_error(&value.err().unwrap());
} else {
println!("{} - {}", name.unwrap(), value.unwrap());
}
}
})
.map_err(|e| trace_error(&e));
}
})
.map_err(|e| trace_error(&e))
}); });
} }