Merge pull request #447 from matthiasbeyer/imag-store/get

Imag store/get
This commit is contained in:
Matthias Beyer 2016-05-28 11:35:15 +02:00
commit eab439f96c
4 changed files with 90 additions and 13 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",
@ -56,10 +58,11 @@ fn main() {
|name| {
debug!("Call: {}", name);
match name {
"create" => create(&rt),
"retrieve" => retrieve(&rt),
"update" => update(&rt),
"delete" => delete(&rt),
"create" => create(&rt),
"delete" => delete(&rt),
"get" => get(&rt),
"retrieve" => retrieve(&rt),
"update" => update(&rt),
_ => {
debug!("Unknown command");
// More error handling

View file

@ -35,7 +35,7 @@ pub fn retrieve(rt: &Runtime) {
});
}
fn print_entry(rt: &Runtime, scmd: &ArgMatches, e: FileLockEntry) {
pub fn print_entry(rt: &Runtime, scmd: &ArgMatches, e: FileLockEntry) {
if do_print_raw(scmd) {
debug!("Printing raw content...");
println!("{}", e.to_str());

View file

@ -53,7 +53,50 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
)
.subcommand(SubCommand::with_name("retrieve")
.about("Get an entry from the store")
.about("Retrieve an entry from the store (implicitely creates the entry)")
.version("0.1")
.arg(Arg::with_name("id")
.long("id")
.short("i")
.takes_value(true)
.required(true)
.help("Retreive by Store Path, where root (/) is the store itself"))
.arg(Arg::with_name("content")
.long("content")
.short("c")
.help("Print content"))
.arg(Arg::with_name("header")
.long("header")
.short("h")
.help("Print header"))
.arg(Arg::with_name("header-json")
.long("header-json")
.short("j")
.help("Print header as json"))
.arg(Arg::with_name("raw")
.long("raw")
.short("r")
.help("Print Entries as they are in the store"))
.subcommand(SubCommand::with_name("filter-header")
.about("Retrieve Entries by filtering")
.version("0.1")
.arg(Arg::with_name("header-field-where")
.long("where")
.short("w")
.takes_value(true)
.help("Filter with 'header.field=foo' where the header field 'header.field' equals 'foo'")
)
.arg(Arg::with_name("header-field-grep")
.long("grep")
.short("g")
.takes_value(true)
.help("Filter with 'header.field=[a-zA-Z0-9]*' where the header field 'header.field' matches '[a-zA-Z0-9]*'"))
)
)
.subcommand(SubCommand::with_name("get")
.about("Get an entry from the store (fails if non-existent)")
.version("0.1")
.arg(Arg::with_name("id")
.long("id")