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() rt.cli()
.subcommand_matches("retrieve") .subcommand_matches("retrieve")
.map(|scmd| { .map(|scmd| {
scmd.value_of("id") // unwrap() is safe as arg is required
.map(|id| { let id = scmd.value_of("id").unwrap();
let path = PathBuf::from(id); let path = PathBuf::from(id);
let path = try!(StoreId::new(Some(rt.store().path().clone()), path) let store = Some(rt.store().path().clone());
.map_err_trace_exit(1)); let path = try!(StoreId::new(store, path).map_err_trace_exit(1));
debug!("path = {:?}", path); debug!("path = {:?}", path);
rt.store() rt.store()
// "id" must be present, enforced via clap spec
.retrieve(path) .retrieve(path)
.map(|e| print_entry(rt, scmd, e)) .map(|e| print_entry(rt, scmd, e))
.map_dbg_str("No entry") .map_dbg_str("No entry")
.map_dbg(|e| format!("{:?}", e)) .map_dbg(|e| format!("{:?}", e))
.map_err_trace() .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)") .about("Retrieve an entry from the store (implicitely creates the entry)")
.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("Retreive by Store Path, where root (/) is the store itself")) .help("Retreive by Store Path, where root (/) is the store itself"))