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; use libimagrt::setup::generate_runtime_setup;
mod error;
mod ui;
mod create; mod create;
mod retrieve;
mod update;
mod delete; mod delete;
mod error;
mod get;
mod retrieve;
mod ui;
mod update;
mod util; mod util;
use ui::build_ui;
use create::create; use create::create;
use retrieve::retrieve;
use update::update;
use delete::delete; use delete::delete;
use get::get;
use retrieve::retrieve;
use ui::build_ui;
use update::update;
fn main() { fn main() {
let rt = generate_runtime_setup("imag-store", let rt = generate_runtime_setup("imag-store",
@ -56,10 +58,11 @@ fn main() {
|name| { |name| {
debug!("Call: {}", name); debug!("Call: {}", name);
match name { match name {
"create" => create(&rt), "create" => create(&rt),
"retrieve" => retrieve(&rt), "delete" => delete(&rt),
"update" => update(&rt), "get" => get(&rt),
"delete" => delete(&rt), "retrieve" => retrieve(&rt),
"update" => update(&rt),
_ => { _ => {
debug!("Unknown command"); debug!("Unknown command");
// More error handling // More error handling