Rewrite delete() to use positional arg

This commit is contained in:
Matthias Beyer 2017-09-04 16:51:18 +02:00
parent 9e9c04e5f3
commit 7b1ffdfa4b
2 changed files with 12 additions and 20 deletions

View file

@ -21,29 +21,22 @@ use std::path::PathBuf;
use libimagrt::runtime::Runtime;
use libimagerror::trace::MapErrTrace;
use libimagerror::trace::trace_error_exit;
use libimagstore::storeid::StoreId;
use libimagutil::warn_exit::warn_exit;
use libimagutil::warn_result::*;
pub fn delete(rt: &Runtime) {
rt.cli()
.subcommand_matches("delete")
.map(|sub| {
sub.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!("Deleting file at {:?}", id);
let scmd = rt.cli().subcommand_matches("delete").unwrap();
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!("Deleting file at {:?}", id);
rt.store()
.delete(path)
.map_warn_err(|e| format!("Error: {:?}", e))
.map_err_trace_exit(1)
})
.or_else(|| warn_exit("No ID passed. Will exit now", 1))
})
.or_else(|| warn_exit("No subcommand 'delete'. Will exit now", 1));
let _ = rt.store()
.delete(path)
.map_warn_err(|e| format!("Error: {:?}", e))
.map_err_trace_exit(1);
}
#[cfg(test)]

View file

@ -179,8 +179,7 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
.about("Delete an entry from the store")
.version("0.1")
.arg(Arg::with_name("id")
.long("id")
.short("i")
.index(1)
.takes_value(true)
.required(true)
.help("Remove Store Entry with this path. Root (/) is the store itself")