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 libimagrt::runtime::Runtime;
|
||||
use libimagerror::trace::{trace_error, trace_error_exit};
|
||||
use libimagerror::trace::trace_error_exit;
|
||||
use libimagstore::storeid::StoreId;
|
||||
|
||||
use retrieve::print_entry;
|
||||
|
||||
pub fn get(rt: &Runtime) {
|
||||
rt.cli()
|
||||
.subcommand_matches("get")
|
||||
.map(|scmd| {
|
||||
scmd.value_of("id")
|
||||
.map(|id| {
|
||||
let path = PathBuf::from(id);
|
||||
let path = match StoreId::new(Some(rt.store().path().clone()), path) {
|
||||
Err(e) => trace_error_exit(&e, 1),
|
||||
Ok(p) => p,
|
||||
};
|
||||
debug!("path = {:?}", path);
|
||||
let scmd = rt.cli().subcommand_matches("get").unwrap();
|
||||
|
||||
match rt.store().get(path) {
|
||||
Ok(Some(entry)) => print_entry(rt, scmd, entry),
|
||||
Ok(None) => info!("No entry found"),
|
||||
Err(e) => trace_error(&e),
|
||||
}
|
||||
})
|
||||
});
|
||||
let id = scmd.value_of("id").unwrap(); // safe by clap
|
||||
let path = PathBuf::from(id);
|
||||
let store = Some(rt.store().path().clone());
|
||||
let path = StoreId::new(store, path).unwrap_or_else(|e| trace_error_exit(&e, 1));
|
||||
debug!("path = {:?}", path);
|
||||
|
||||
let _ = match rt.store().get(path) {
|
||||
Ok(Some(entry)) => print_entry(rt, scmd, entry),
|
||||
Ok(None) => info!("No entry found"),
|
||||
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)")
|
||||
.version("0.1")
|
||||
.arg(Arg::with_name("id")
|
||||
.long("id")
|
||||
.short("i")
|
||||
.index(1)
|
||||
.takes_value(true)
|
||||
.required(true)
|
||||
.help("Retrieve by Store Path, where root (/) is the store itself")
|
||||
|
|
Loading…
Reference in a new issue