Implement get() functionality
This commit is contained in:
parent
203e649b4f
commit
95c640c1e9
2 changed files with 45 additions and 11 deletions
31
imag-store/src/get.rs
Normal file
31
imag-store/src/get.rs
Normal 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),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
@ -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",
|
||||||
|
@ -57,9 +59,10 @@ fn main() {
|
||||||
debug!("Call: {}", name);
|
debug!("Call: {}", name);
|
||||||
match name {
|
match name {
|
||||||
"create" => create(&rt),
|
"create" => create(&rt),
|
||||||
|
"delete" => delete(&rt),
|
||||||
|
"get" => get(&rt),
|
||||||
"retrieve" => retrieve(&rt),
|
"retrieve" => retrieve(&rt),
|
||||||
"update" => update(&rt),
|
"update" => update(&rt),
|
||||||
"delete" => delete(&rt),
|
|
||||||
_ => {
|
_ => {
|
||||||
debug!("Unknown command");
|
debug!("Unknown command");
|
||||||
// More error handling
|
// More error handling
|
||||||
|
|
Loading…
Reference in a new issue