imag/imag-store/src/delete.rs

38 lines
1.1 KiB
Rust
Raw Normal View History

use libimagstore::storeid::build_entry_path;
2016-01-23 15:29:04 +00:00
use libimagrt::runtime::Runtime;
use libimagerror::trace::trace_error_exit;
2016-01-23 15:29:04 +00:00
pub fn delete(rt: &Runtime) {
2016-01-26 18:59:55 +00:00
use std::process::exit;
rt.cli()
.subcommand_matches("delete")
.map(|sub| {
sub.value_of("id")
.map(|id| {
let path = build_entry_path(rt.store(), id);
if path.is_err() {
trace_error_exit(&path.unwrap_err(), 1);
}
let path = path.unwrap();
2016-01-26 18:59:55 +00:00
debug!("Deleting file at {:?}", id);
2016-01-26 18:59:55 +00:00
rt.store()
.delete(path)
2016-01-26 18:59:55 +00:00
.map_err(|e| {
warn!("Error: {:?}", e);
exit(1);
})
})
.or_else(|| {
warn!("No ID passed. Will exit now");
exit(1);
})
})
.or_else(|| {
warn!("No subcommand 'delete'. Will exit now");
exit(1);
});
2016-01-23 15:29:04 +00:00
}