imag/imag-counter/src/create.rs

30 lines
959 B
Rust
Raw Normal View History

2016-02-13 19:25:11 +00:00
use std::str::FromStr;
use std::process::exit;
use libimagrt::runtime::Runtime;
use libimagerror::trace::trace_error;
2016-02-13 19:25:11 +00:00
use libimagcounter::counter::Counter;
pub fn create(rt: &Runtime) {
rt.cli()
.subcommand_matches("create")
.map(|scmd| {
debug!("Found 'create' subcommand...");
let name = scmd.value_of("name").unwrap(); // safe because clap enforces
let init : i64 = scmd
.value_of("initval")
.and_then(|i| FromStr::from_str(i).ok())
.unwrap_or(0);
match Counter::new(rt.store(), String::from(name), init) {
2016-02-13 19:25:11 +00:00
Err(e) => {
warn!("Could not create Counter '{}' with initial value '{}'", name, init);
trace_error(&e);
exit(1);
},
Ok(_) => info!("Created Counter '{}' with initial value '{}'", name, init),
}
});
}