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 libimagrt::runtime::Runtime;
use libimagerror::trace::MapErrTrace; use libimagerror::trace::MapErrTrace;
use libimagerror::trace::trace_error_exit;
use libimagstore::storeid::StoreId; use libimagstore::storeid::StoreId;
use libimagutil::warn_exit::warn_exit;
use libimagutil::warn_result::*; use libimagutil::warn_result::*;
pub fn delete(rt: &Runtime) { pub fn delete(rt: &Runtime) {
rt.cli() let scmd = rt.cli().subcommand_matches("delete").unwrap();
.subcommand_matches("delete") let id = scmd.value_of("id").unwrap(); // safe by clap
.map(|sub| { let path = PathBuf::from(id);
sub.value_of("id") let store = Some(rt.store().path().clone());
.map(|id| { let path = StoreId::new(store, path).unwrap_or_else(|e| trace_error_exit(&e, 1));
let path = PathBuf::from(id); debug!("Deleting file at {:?}", id);
let path = try!(StoreId::new(Some(rt.store().path().clone()), path)
.map_err_trace_exit(1));
debug!("Deleting file at {:?}", id);
rt.store() let _ = rt.store()
.delete(path) .delete(path)
.map_warn_err(|e| format!("Error: {:?}", e)) .map_warn_err(|e| format!("Error: {:?}", e))
.map_err_trace_exit(1) .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));
} }
#[cfg(test)] #[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") .about("Delete an entry from the store")
.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("Remove Store Entry with this path. Root (/) is the store itself") .help("Remove Store Entry with this path. Root (/) is the store itself")