Rewrite get() to use positional arg

This commit is contained in:
Matthias Beyer 2017-09-04 16:44:23 +02:00
parent 9dde4731f2
commit 381223efd9
2 changed files with 14 additions and 21 deletions

View file

@ -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| {
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);
match rt.store().get(path) { let id = scmd.value_of("id").unwrap(); // safe by clap
Ok(Some(entry)) => print_entry(rt, scmd, entry), let path = PathBuf::from(id);
Ok(None) => info!("No entry found"), let store = Some(rt.store().path().clone());
Err(e) => trace_error(&e), 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),
};
} }

View file

@ -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")