Rewrite get() to use positional arg
This commit is contained in:
parent
9dde4731f2
commit
381223efd9
2 changed files with 14 additions and 21 deletions
|
@ -20,30 +20,24 @@
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagerror::trace::{trace_error, trace_error_exit};
|
use libimagerror::trace::trace_error_exit;
|
||||||
use libimagstore::storeid::StoreId;
|
use libimagstore::storeid::StoreId;
|
||||||
|
|
||||||
use retrieve::print_entry;
|
use retrieve::print_entry;
|
||||||
|
|
||||||
pub fn get(rt: &Runtime) {
|
pub fn get(rt: &Runtime) {
|
||||||
rt.cli()
|
let scmd = rt.cli().subcommand_matches("get").unwrap();
|
||||||
.subcommand_matches("get")
|
|
||||||
.map(|scmd| {
|
let id = scmd.value_of("id").unwrap(); // safe by clap
|
||||||
scmd.value_of("id")
|
|
||||||
.map(|id| {
|
|
||||||
let path = PathBuf::from(id);
|
let path = PathBuf::from(id);
|
||||||
let path = match StoreId::new(Some(rt.store().path().clone()), path) {
|
let store = Some(rt.store().path().clone());
|
||||||
Err(e) => trace_error_exit(&e, 1),
|
let path = StoreId::new(store, path).unwrap_or_else(|e| trace_error_exit(&e, 1));
|
||||||
Ok(p) => p,
|
|
||||||
};
|
|
||||||
debug!("path = {:?}", path);
|
debug!("path = {:?}", path);
|
||||||
|
|
||||||
match rt.store().get(path) {
|
let _ = match rt.store().get(path) {
|
||||||
Ok(Some(entry)) => print_entry(rt, scmd, entry),
|
Ok(Some(entry)) => print_entry(rt, scmd, entry),
|
||||||
Ok(None) => info!("No entry found"),
|
Ok(None) => info!("No entry found"),
|
||||||
Err(e) => trace_error(&e),
|
Err(e) => trace_error_exit(&e, 1),
|
||||||
}
|
};
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -111,8 +111,7 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
|
||||||
.about("Get an entry from the store (fails if non-existent)")
|
.about("Get an entry from the store (fails if non-existent)")
|
||||||
.version("0.1")
|
.version("0.1")
|
||||||
.arg(Arg::with_name("id")
|
.arg(Arg::with_name("id")
|
||||||
.long("id")
|
.index(1)
|
||||||
.short("i")
|
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.required(true)
|
.required(true)
|
||||||
.help("Retrieve by Store Path, where root (/) is the store itself")
|
.help("Retrieve by Store Path, where root (/) is the store itself")
|
||||||
|
|
Loading…
Reference in a new issue