Implement Store::retrieve() interface
Rename: read.rs -> retrieve.rs
This commit is contained in:
parent
dbd6388946
commit
9c0796d7b3
3 changed files with 87 additions and 8 deletions
|
@ -13,13 +13,13 @@ use std::process::exit;
|
||||||
mod error;
|
mod error;
|
||||||
mod ui;
|
mod ui;
|
||||||
mod create;
|
mod create;
|
||||||
mod read;
|
mod retrieve;
|
||||||
mod update;
|
mod update;
|
||||||
mod delete;
|
mod delete;
|
||||||
|
|
||||||
use ui::build_ui;
|
use ui::build_ui;
|
||||||
use create::create;
|
use create::create;
|
||||||
use read::read;
|
use retrieve::retrieve;
|
||||||
use update::update;
|
use update::update;
|
||||||
use delete::delete;
|
use delete::delete;
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ fn main() {
|
||||||
debug!("Call: {}", name);
|
debug!("Call: {}", name);
|
||||||
match name {
|
match name {
|
||||||
"create" => create(&rt),
|
"create" => create(&rt),
|
||||||
"read" => read(&rt),
|
"retrieve" => retrieve(&rt),
|
||||||
"update" => update(&rt),
|
"update" => update(&rt),
|
||||||
"delete" => delete(&rt),
|
"delete" => delete(&rt),
|
||||||
_ => {
|
_ => {
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
use libimagrt::runtime::Runtime;
|
|
||||||
|
|
||||||
pub fn read(rt: &Runtime) {
|
|
||||||
}
|
|
||||||
|
|
84
imag-store/src/retrieve.rs
Normal file
84
imag-store/src/retrieve.rs
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use std::ops::Deref;
|
||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
|
use clap::ArgMatches;
|
||||||
|
use toml::Value;
|
||||||
|
|
||||||
|
use libimagstore::store::FileLockEntry;
|
||||||
|
use libimagrt::runtime::Runtime;
|
||||||
|
|
||||||
|
use util::build_entry_path;
|
||||||
|
|
||||||
|
pub fn retrieve(rt: &Runtime) {
|
||||||
|
rt.cli()
|
||||||
|
.subcommand_matches("retrieve")
|
||||||
|
.map(|scmd| {
|
||||||
|
let path = scmd.value_of("id").map(|id| build_entry_path(rt, id)).unwrap();
|
||||||
|
debug!("path = {:?}", path);
|
||||||
|
rt.store()
|
||||||
|
// "id" must be present, enforced via clap spec
|
||||||
|
.retrieve(path)
|
||||||
|
.map(|e| print_entry(rt, scmd, e))
|
||||||
|
.map_err(|e| {
|
||||||
|
debug!("No entry.");
|
||||||
|
debug!("{}", e);
|
||||||
|
})
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn print_entry(rt: &Runtime, scmd: &ArgMatches, e: FileLockEntry) {
|
||||||
|
if do_print_raw(scmd) {
|
||||||
|
debug!("Printing raw content...");
|
||||||
|
println!("{}", e.deref().to_str());
|
||||||
|
} else if do_filter(scmd) {
|
||||||
|
debug!("Filtering...");
|
||||||
|
warn!("Filtering via header specs is currently now supported.");
|
||||||
|
warn!("Will fail now!");
|
||||||
|
unimplemented!()
|
||||||
|
} else {
|
||||||
|
debug!("Printing structured...");
|
||||||
|
let entry = e.deref();
|
||||||
|
if do_print_header(scmd) {
|
||||||
|
debug!("Printing header...");
|
||||||
|
if do_print_header_as_json(rt.cli()) {
|
||||||
|
debug!("Printing header as json...");
|
||||||
|
warn!("Printing as JSON currently not supported.");
|
||||||
|
warn!("Will fail now!");
|
||||||
|
unimplemented!()
|
||||||
|
} else {
|
||||||
|
debug!("Printing header as TOML...");
|
||||||
|
// We have to Value::Table() for Display
|
||||||
|
println!("{}", Value::Table(entry.get_header().toml().clone()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if do_print_content(scmd) {
|
||||||
|
debug!("Printing content...");
|
||||||
|
println!("{}", entry.get_content());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn do_print_header(m: &ArgMatches) -> bool {
|
||||||
|
m.is_present("header")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn do_print_header_as_json(m: &ArgMatches) -> bool {
|
||||||
|
m.is_present("header-json")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn do_print_content(m: &ArgMatches) -> bool {
|
||||||
|
m.is_present("content")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn do_print_raw(m: &ArgMatches) -> bool {
|
||||||
|
m.is_present("raw")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn do_filter(m: &ArgMatches) -> bool {
|
||||||
|
m.subcommand_matches("filter-header").is_some()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue