Rewrite retrieve() to use positional arg

This commit is contained in:
Matthias Beyer 2017-09-04 16:42:31 +02:00
parent a71732be49
commit 9dde4731f2
2 changed files with 13 additions and 16 deletions

View file

@ -31,21 +31,19 @@ pub fn retrieve(rt: &Runtime) {
rt.cli()
.subcommand_matches("retrieve")
.map(|scmd| {
scmd.value_of("id")
.map(|id| {
let path = PathBuf::from(id);
let path = try!(StoreId::new(Some(rt.store().path().clone()), path)
.map_err_trace_exit(1));
debug!("path = {:?}", path);
// unwrap() is safe as arg is required
let id = scmd.value_of("id").unwrap();
let path = PathBuf::from(id);
let store = Some(rt.store().path().clone());
let path = try!(StoreId::new(store, path).map_err_trace_exit(1));
debug!("path = {:?}", path);
rt.store()
// "id" must be present, enforced via clap spec
.retrieve(path)
.map(|e| print_entry(rt, scmd, e))
.map_dbg_str("No entry")
.map_dbg(|e| format!("{:?}", e))
.map_err_trace()
})
rt.store()
.retrieve(path)
.map(|e| print_entry(rt, scmd, e))
.map_dbg_str("No entry")
.map_dbg(|e| format!("{:?}", e))
.map_err_trace()
});
}

View file

@ -69,8 +69,7 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
.about("Retrieve an entry from the store (implicitely creates the entry)")
.version("0.1")
.arg(Arg::with_name("id")
.long("id")
.short("i")
.index(1)
.takes_value(true)
.required(true)
.help("Retreive by Store Path, where root (/) is the store itself"))