Implement get() functionality

This commit is contained in:
Matthias Beyer 2016-05-27 11:26:22 +02:00
parent 203e649b4f
commit 95c640c1e9
2 changed files with 45 additions and 11 deletions

31
imag-store/src/get.rs Normal file
View file

@ -0,0 +1,31 @@
use std::process::exit;
use libimagstore::storeid::build_entry_path;
use libimagrt::runtime::Runtime;
use libimagerror::trace::trace_error;
use retrieve::print_entry;
pub fn get(rt: &Runtime) {
rt.cli()
.subcommand_matches("get")
.map(|scmd| {
scmd.value_of("id")
.map(|id| {
let path = build_entry_path(rt.store(), id);
if path.is_err() {
trace_error(&path.unwrap_err());
exit(1);
}
let path = path.unwrap();
debug!("path = {:?}", path);
match rt.store().get(path) {
Ok(Some(entry)) => print_entry(rt, scmd, entry),
Ok(None) => info!("No entry found"),
Err(e) => trace_error(&e),
}
})
});
}

View file

@ -26,19 +26,21 @@ extern crate libimagutil;
use libimagrt::setup::generate_runtime_setup;
mod error;
mod ui;
mod create;
mod retrieve;
mod update;
mod delete;
mod error;
mod get;
mod retrieve;
mod ui;
mod update;
mod util;
use ui::build_ui;
use create::create;
use retrieve::retrieve;
use update::update;
use delete::delete;
use get::get;
use retrieve::retrieve;
use ui::build_ui;
use update::update;
fn main() {
let rt = generate_runtime_setup("imag-store",
@ -57,9 +59,10 @@ fn main() {
debug!("Call: {}", name);
match name {
"create" => create(&rt),
"delete" => delete(&rt),
"get" => get(&rt),
"retrieve" => retrieve(&rt),
"update" => update(&rt),
"delete" => delete(&rt),
_ => {
debug!("Unknown command");
// More error handling