Remove magic constants in trace_unwrap_exit/map_err_trace_exit_unwrap calls
This patch removes the magic constant we used when calling `trace_unwrap_exit()` or `map_err_trace_exit_unwrap()`. We used to call it with `1` as parameter, where the number was the exit code to use. Now the implementation of the function does it automatically (using 1 (one) as exit code). All calls of these functions were fixed. Thanks to vim this was easy. Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
01fa19aade
commit
90eaeb642a
53 changed files with 377 additions and 362 deletions
|
@ -87,7 +87,7 @@ fn main() {
|
||||||
other => {
|
other => {
|
||||||
debug!("Unknown command");
|
debug!("Unknown command");
|
||||||
let _ = rt.handle_unknown_subcommand("imag-annotation", other, rt.cli())
|
let _ = rt.handle_unknown_subcommand("imag-annotation", other, rt.cli())
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.code()
|
.code()
|
||||||
.map(::std::process::exit);
|
.map(::std::process::exit);
|
||||||
},
|
},
|
||||||
|
@ -97,27 +97,27 @@ fn main() {
|
||||||
|
|
||||||
fn add(rt: &Runtime) {
|
fn add(rt: &Runtime) {
|
||||||
let scmd = rt.cli().subcommand_matches("add").unwrap(); // safed by main()
|
let scmd = rt.cli().subcommand_matches("add").unwrap(); // safed by main()
|
||||||
let mut ids = rt.ids::<::ui::PathProvider>().map_err_trace_exit_unwrap(1).into_iter();
|
let mut ids = rt.ids::<::ui::PathProvider>().map_err_trace_exit_unwrap().into_iter();
|
||||||
|
|
||||||
if let Some(first) = ids.next() {
|
if let Some(first) = ids.next() {
|
||||||
let mut annotation = rt.store()
|
let mut annotation = rt.store()
|
||||||
.get(first.clone())
|
.get(first.clone())
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.ok_or_else(|| EM::EntryNotFound(first.local_display_string()))
|
.ok_or_else(|| EM::EntryNotFound(first.local_display_string()))
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.annotate(rt.store())
|
.annotate(rt.store())
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let _ = annotation.edit_content(&rt).map_err_trace_exit_unwrap(1);
|
let _ = annotation.edit_content(&rt).map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
for id in ids {
|
for id in ids {
|
||||||
let mut entry = rt.store().get(id.clone())
|
let mut entry = rt.store().get(id.clone())
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.ok_or_else(|| format_err!("Not found: {}", id.local_display_string()))
|
.ok_or_else(|| format_err!("Not found: {}", id.local_display_string()))
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let _ = entry.add_internal_link(&mut annotation).map_err_trace_exit_unwrap(1);
|
let _ = entry.add_internal_link(&mut annotation).map_err_trace_exit_unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
if !scmd.is_present("dont-print-name") {
|
if !scmd.is_present("dont-print-name") {
|
||||||
|
@ -125,7 +125,7 @@ fn add(rt: &Runtime) {
|
||||||
.get_header()
|
.get_header()
|
||||||
.read_string("annotation.name")
|
.read_string("annotation.name")
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
{
|
{
|
||||||
let _ = writeln!(rt.stdout(), "Name of the annotation: {}", annotation_id)
|
let _ = writeln!(rt.stdout(), "Name of the annotation: {}", annotation_id)
|
||||||
.to_exit_code()
|
.to_exit_code()
|
||||||
|
@ -144,19 +144,19 @@ fn remove(rt: &Runtime) {
|
||||||
let scmd = rt.cli().subcommand_matches("remove").unwrap(); // safed by main()
|
let scmd = rt.cli().subcommand_matches("remove").unwrap(); // safed by main()
|
||||||
let annotation_name = scmd.value_of("annotation_name").unwrap(); // safed by clap
|
let annotation_name = scmd.value_of("annotation_name").unwrap(); // safed by clap
|
||||||
let delete = scmd.is_present("delete-annotation");
|
let delete = scmd.is_present("delete-annotation");
|
||||||
let ids = rt.ids::<::ui::PathProvider>().map_err_trace_exit_unwrap(1);
|
let ids = rt.ids::<::ui::PathProvider>().map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
ids.into_iter().for_each(|id| {
|
ids.into_iter().for_each(|id| {
|
||||||
let mut entry = rt.store()
|
let mut entry = rt.store()
|
||||||
.get(id.clone())
|
.get(id.clone())
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.ok_or_else(|| EM::EntryNotFound(id.local_display_string()))
|
.ok_or_else(|| EM::EntryNotFound(id.local_display_string()))
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let annotation = entry
|
let annotation = entry
|
||||||
.denotate(rt.store(), annotation_name)
|
.denotate(rt.store(), annotation_name)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
if delete {
|
if delete {
|
||||||
debug!("Deleting annotation object");
|
debug!("Deleting annotation object");
|
||||||
|
@ -167,7 +167,7 @@ fn remove(rt: &Runtime) {
|
||||||
let _ = rt
|
let _ = rt
|
||||||
.store()
|
.store()
|
||||||
.delete(loc)
|
.delete(loc)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
} else {
|
} else {
|
||||||
warn!("Not having annotation object, cannot delete!");
|
warn!("Not having annotation object, cannot delete!");
|
||||||
}
|
}
|
||||||
|
@ -181,7 +181,7 @@ fn remove(rt: &Runtime) {
|
||||||
fn list(rt: &Runtime) {
|
fn list(rt: &Runtime) {
|
||||||
let scmd = rt.cli().subcommand_matches("list").unwrap(); // safed by clap
|
let scmd = rt.cli().subcommand_matches("list").unwrap(); // safed by clap
|
||||||
let with_text = scmd.is_present("list-with-text");
|
let with_text = scmd.is_present("list-with-text");
|
||||||
let ids = rt.ids::<::ui::PathProvider>().map_err_trace_exit_unwrap(1);
|
let ids = rt.ids::<::ui::PathProvider>().map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
if ids.len() != 0 {
|
if ids.len() != 0 {
|
||||||
let _ = ids
|
let _ = ids
|
||||||
|
@ -190,16 +190,16 @@ fn list(rt: &Runtime) {
|
||||||
let _ = rt
|
let _ = rt
|
||||||
.store()
|
.store()
|
||||||
.get(id.clone())
|
.get(id.clone())
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.ok_or_else(|| EM::EntryNotFound(id.local_display_string()))
|
.ok_or_else(|| EM::EntryNotFound(id.local_display_string()))
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.annotations()
|
.annotations()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.into_get_iter(rt.store())
|
.into_get_iter(rt.store())
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.map(|opt| opt.ok_or_else(|| format_err!("Cannot find entry")))
|
.map(|opt| opt.ok_or_else(|| format_err!("Cannot find entry")))
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.for_each(|(i, entry)| list_annotation(&rt, i, entry, with_text));
|
.for_each(|(i, entry)| list_annotation(&rt, i, entry, with_text));
|
||||||
});
|
});
|
||||||
|
@ -207,11 +207,11 @@ fn list(rt: &Runtime) {
|
||||||
// show them all
|
// show them all
|
||||||
rt.store()
|
rt.store()
|
||||||
.all_annotations()
|
.all_annotations()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.into_get_iter(rt.store())
|
.into_get_iter(rt.store())
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.map(|opt| opt.ok_or_else(|| format_err!("Cannot find entry")))
|
.map(|opt| opt.ok_or_else(|| format_err!("Cannot find entry")))
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.for_each(|(i, entry)| list_annotation(&rt, i, entry, with_text));
|
.for_each(|(i, entry)| list_annotation(&rt, i, entry, with_text));
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,7 @@ impl IdPathProvider for PathProvider {
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
.map(|pb| pb.into_storeid())
|
.map(|pb| pb.into_storeid())
|
||||||
.collect::<Result<Vec<_>, _>>()
|
.collect::<Result<Vec<_>, _>>()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
},
|
},
|
||||||
|
|
||||||
("remove", Some(subm)) => {
|
("remove", Some(subm)) => {
|
||||||
|
@ -124,7 +124,7 @@ impl IdPathProvider for PathProvider {
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
.map(|pb| pb.into_storeid())
|
.map(|pb| pb.into_storeid())
|
||||||
.collect::<Result<Vec<_>, _>>()
|
.collect::<Result<Vec<_>, _>>()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
},
|
},
|
||||||
|
|
||||||
("list", Some(subm)) => {
|
("list", Some(subm)) => {
|
||||||
|
@ -138,7 +138,7 @@ impl IdPathProvider for PathProvider {
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
.map(|pb| pb.into_storeid())
|
.map(|pb| pb.into_storeid())
|
||||||
.collect::<Result<Vec<_>, _>>()
|
.collect::<Result<Vec<_>, _>>()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
},
|
},
|
||||||
|
|
||||||
(other, _) => {
|
(other, _) => {
|
||||||
|
|
|
@ -81,7 +81,7 @@ fn main() {
|
||||||
other => {
|
other => {
|
||||||
debug!("Unknown command");
|
debug!("Unknown command");
|
||||||
let _ = rt.handle_unknown_subcommand("imag-category", other, rt.cli())
|
let _ = rt.handle_unknown_subcommand("imag-category", other, rt.cli())
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.code()
|
.code()
|
||||||
.map(::std::process::exit);
|
.map(::std::process::exit);
|
||||||
},
|
},
|
||||||
|
@ -92,11 +92,11 @@ fn main() {
|
||||||
fn set(rt: &Runtime) {
|
fn set(rt: &Runtime) {
|
||||||
let scmd = rt.cli().subcommand_matches("set").unwrap(); // safed by main()
|
let scmd = rt.cli().subcommand_matches("set").unwrap(); // safed by main()
|
||||||
let name = scmd.value_of("set-name").map(String::from).unwrap(); // safed by clap
|
let name = scmd.value_of("set-name").map(String::from).unwrap(); // safed by clap
|
||||||
let sids = rt.ids::<::ui::PathProvider>().map_err_trace_exit_unwrap(1);
|
let sids = rt.ids::<::ui::PathProvider>().map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
StoreIdIterator::new(Box::new(sids.into_iter().map(Ok)))
|
StoreIdIterator::new(Box::new(sids.into_iter().map(Ok)))
|
||||||
.into_get_iter(rt.store())
|
.into_get_iter(rt.store())
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.map(|o| o.unwrap_or_else(|| {
|
.map(|o| o.unwrap_or_else(|| {
|
||||||
error!("Did not find one entry");
|
error!("Did not find one entry");
|
||||||
::std::process::exit(1)
|
::std::process::exit(1)
|
||||||
|
@ -104,23 +104,23 @@ fn set(rt: &Runtime) {
|
||||||
.for_each(|mut entry| {
|
.for_each(|mut entry| {
|
||||||
let _ = entry
|
let _ = entry
|
||||||
.set_category_checked(rt.store(), &name)
|
.set_category_checked(rt.store(), &name)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get(rt: &Runtime) {
|
fn get(rt: &Runtime) {
|
||||||
let sids = rt.ids::<::ui::PathProvider>().map_err_trace_exit_unwrap(1);
|
let sids = rt.ids::<::ui::PathProvider>().map_err_trace_exit_unwrap();
|
||||||
let out = rt.stdout();
|
let out = rt.stdout();
|
||||||
let mut outlock = out.lock();
|
let mut outlock = out.lock();
|
||||||
|
|
||||||
StoreIdIterator::new(Box::new(sids.into_iter().map(Ok)))
|
StoreIdIterator::new(Box::new(sids.into_iter().map(Ok)))
|
||||||
.into_get_iter(rt.store())
|
.into_get_iter(rt.store())
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.map(|o| o.unwrap_or_else(|| {
|
.map(|o| o.unwrap_or_else(|| {
|
||||||
error!("Did not find one entry");
|
error!("Did not find one entry");
|
||||||
::std::process::exit(1)
|
::std::process::exit(1)
|
||||||
}))
|
}))
|
||||||
.map(|entry| entry.get_category().map_err_trace_exit_unwrap(1))
|
.map(|entry| entry.get_category().map_err_trace_exit_unwrap())
|
||||||
.for_each(|name| {
|
.for_each(|name| {
|
||||||
let _ = writeln!(outlock, "{}", name).to_exit_code().unwrap_or_exit();
|
let _ = writeln!(outlock, "{}", name).to_exit_code().unwrap_or_exit();
|
||||||
})
|
})
|
||||||
|
@ -130,15 +130,15 @@ fn list_category(rt: &Runtime) {
|
||||||
let scmd = rt.cli().subcommand_matches("list-category").unwrap(); // safed by main()
|
let scmd = rt.cli().subcommand_matches("list-category").unwrap(); // safed by main()
|
||||||
let name = scmd.value_of("list-category-name").map(String::from).unwrap(); // safed by clap
|
let name = scmd.value_of("list-category-name").map(String::from).unwrap(); // safed by clap
|
||||||
|
|
||||||
if let Some(category) = rt.store().get_category_by_name(&name).map_err_trace_exit_unwrap(1) {
|
if let Some(category) = rt.store().get_category_by_name(&name).map_err_trace_exit_unwrap() {
|
||||||
let out = rt.stdout();
|
let out = rt.stdout();
|
||||||
let mut outlock = out.lock();
|
let mut outlock = out.lock();
|
||||||
|
|
||||||
category
|
category
|
||||||
.get_entries(rt.store())
|
.get_entries(rt.store())
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.for_each(|entry| {
|
.for_each(|entry| {
|
||||||
writeln!(outlock, "{}", entry.map_err_trace_exit_unwrap(1).get_location())
|
writeln!(outlock, "{}", entry.map_err_trace_exit_unwrap().get_location())
|
||||||
.to_exit_code()
|
.to_exit_code()
|
||||||
.unwrap_or_exit();
|
.unwrap_or_exit();
|
||||||
})
|
})
|
||||||
|
@ -155,7 +155,7 @@ fn create_category(rt: &Runtime) {
|
||||||
let _ = rt
|
let _ = rt
|
||||||
.store()
|
.store()
|
||||||
.create_category(&name)
|
.create_category(&name)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn delete_category(rt: &Runtime) {
|
fn delete_category(rt: &Runtime) {
|
||||||
|
@ -170,14 +170,14 @@ fn delete_category(rt: &Runtime) {
|
||||||
::std::process::exit(1)
|
::std::process::exit(1)
|
||||||
});
|
});
|
||||||
let mut output = rt.stdout();
|
let mut output = rt.stdout();
|
||||||
let answer = ask_bool(&ques, Some(false), &mut input, &mut output).map_err_trace_exit_unwrap(1);
|
let answer = ask_bool(&ques, Some(false), &mut input, &mut output).map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
if answer {
|
if answer {
|
||||||
info!("Deleting category '{}'", name);
|
info!("Deleting category '{}'", name);
|
||||||
let _ = rt
|
let _ = rt
|
||||||
.store()
|
.store()
|
||||||
.delete_category(&name)
|
.delete_category(&name)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
} else {
|
} else {
|
||||||
info!("Not doing anything");
|
info!("Not doing anything");
|
||||||
}
|
}
|
||||||
|
@ -189,9 +189,9 @@ fn list_categories(rt: &Runtime) {
|
||||||
|
|
||||||
rt.store()
|
rt.store()
|
||||||
.all_category_names()
|
.all_category_names()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.for_each(|name| {
|
.for_each(|name| {
|
||||||
writeln!(outlock, "{}", name.map_err_trace_exit_unwrap(1))
|
writeln!(outlock, "{}", name.map_err_trace_exit_unwrap())
|
||||||
.to_exit_code()
|
.to_exit_code()
|
||||||
.unwrap_or_exit();
|
.unwrap_or_exit();
|
||||||
})
|
})
|
||||||
|
|
|
@ -136,7 +136,7 @@ impl IdPathProvider for PathProvider {
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
.map(|pb| pb.into_storeid())
|
.map(|pb| pb.into_storeid())
|
||||||
.collect::<Result<Vec<_>, _>>()
|
.collect::<Result<Vec<_>, _>>()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
},
|
},
|
||||||
|
|
||||||
("get", Some(subm)) => {
|
("get", Some(subm)) => {
|
||||||
|
@ -150,7 +150,7 @@ impl IdPathProvider for PathProvider {
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
.map(|pb| pb.into_storeid())
|
.map(|pb| pb.into_storeid())
|
||||||
.collect::<Result<Vec<_>, _>>()
|
.collect::<Result<Vec<_>, _>>()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
},
|
},
|
||||||
|
|
||||||
(other, _) => {
|
(other, _) => {
|
||||||
|
|
|
@ -143,12 +143,12 @@ fn main() {
|
||||||
|
|
||||||
let diags = rt.store()
|
let diags = rt.store()
|
||||||
.entries()
|
.entries()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.into_get_iter()
|
.into_get_iter()
|
||||||
.map(|e| {
|
.map(|e| {
|
||||||
e.map_err_trace_exit_unwrap(1)
|
e.map_err_trace_exit_unwrap()
|
||||||
.ok_or_else(|| Error::from(err_msg("Unable to get entry".to_owned())))
|
.ok_or_else(|| Error::from(err_msg("Unable to get entry".to_owned())))
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
})
|
})
|
||||||
.map(|e| {
|
.map(|e| {
|
||||||
let diag = Diagnostic::for_entry(&e);
|
let diag = Diagnostic::for_entry(&e);
|
||||||
|
@ -162,14 +162,14 @@ fn main() {
|
||||||
// The store has an API for it, but the cache size calculation is O(n) and we can do
|
// The store has an API for it, but the cache size calculation is O(n) and we can do
|
||||||
// better by simply flushing the cache each 100 entries
|
// better by simply flushing the cache each 100 entries
|
||||||
if entries_counter > 100 {
|
if entries_counter > 100 {
|
||||||
let _ = rt.store().flush_cache().map_err_trace_exit_unwrap(1);
|
let _ = rt.store().flush_cache().map_err_trace_exit_unwrap();
|
||||||
entries_counter = 0;
|
entries_counter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
diag
|
diag
|
||||||
})
|
})
|
||||||
.collect::<Result<Vec<_>>>()
|
.collect::<Result<Vec<_>>>()
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
spinner.finish();
|
spinner.finish();
|
||||||
let n = diags.len();
|
let n = diags.len();
|
||||||
|
@ -244,7 +244,7 @@ fn main() {
|
||||||
num,
|
num,
|
||||||
path
|
path
|
||||||
.into_pathbuf()
|
.into_pathbuf()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.to_str()
|
.to_str()
|
||||||
.unwrap_or("Failed converting path to string")
|
.unwrap_or("Failed converting path to string")
|
||||||
);
|
);
|
||||||
|
@ -257,7 +257,7 @@ fn main() {
|
||||||
num,
|
num,
|
||||||
path
|
path
|
||||||
.into_pathbuf()
|
.into_pathbuf()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.to_str()
|
.to_str()
|
||||||
.unwrap_or("Failed converting path to string")
|
.unwrap_or("Failed converting path to string")
|
||||||
);
|
);
|
||||||
|
@ -271,7 +271,7 @@ fn get_config(rt: &Runtime, s: &'static str) -> Option<String> {
|
||||||
rt.config().and_then(|cfg| {
|
rt.config().and_then(|cfg| {
|
||||||
cfg.read(s)
|
cfg.read(s)
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.map(|opt| match opt {
|
.map(|opt| match opt {
|
||||||
&Value::String(ref s) => s.to_owned(),
|
&Value::String(ref s) => s.to_owned(),
|
||||||
_ => {
|
_ => {
|
||||||
|
|
|
@ -63,11 +63,11 @@ fn main() {
|
||||||
let edit_header = rt.cli().is_present("edit-header");
|
let edit_header = rt.cli().is_present("edit-header");
|
||||||
let edit_header_only = rt.cli().is_present("edit-header-only");
|
let edit_header_only = rt.cli().is_present("edit-header-only");
|
||||||
|
|
||||||
let sids = rt.ids::<::ui::PathProvider>().map_err_trace_exit_unwrap(1);
|
let sids = rt.ids::<::ui::PathProvider>().map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
StoreIdIterator::new(Box::new(sids.into_iter().map(Ok)))
|
StoreIdIterator::new(Box::new(sids.into_iter().map(Ok)))
|
||||||
.into_get_iter(rt.store())
|
.into_get_iter(rt.store())
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.map(|o| o.unwrap_or_else(|| {
|
.map(|o| o.unwrap_or_else(|| {
|
||||||
error!("Did not find one entry");
|
error!("Did not find one entry");
|
||||||
::std::process::exit(1)
|
::std::process::exit(1)
|
||||||
|
@ -76,15 +76,15 @@ fn main() {
|
||||||
if edit_header {
|
if edit_header {
|
||||||
let _ = entry
|
let _ = entry
|
||||||
.edit_header_and_content(&rt)
|
.edit_header_and_content(&rt)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
} else if edit_header_only {
|
} else if edit_header_only {
|
||||||
let _ = entry
|
let _ = entry
|
||||||
.edit_header(&rt)
|
.edit_header(&rt)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
} else {
|
} else {
|
||||||
let _ = entry
|
let _ = entry
|
||||||
.edit_content(&rt)
|
.edit_content(&rt)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,6 +66,6 @@ impl IdPathProvider for PathProvider {
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
.map(|pb| pb.into_storeid())
|
.map(|pb| pb.into_storeid())
|
||||||
.collect::<Result<Vec<_>, _>>()
|
.collect::<Result<Vec<_>, _>>()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ fn main() {
|
||||||
other => {
|
other => {
|
||||||
debug!("Unknown command");
|
debug!("Unknown command");
|
||||||
let _ = rt.handle_unknown_subcommand("imag-gps", other, rt.cli())
|
let _ = rt.handle_unknown_subcommand("imag-gps", other, rt.cli())
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.code()
|
.code()
|
||||||
.map(::std::process::exit);
|
.map(::std::process::exit);
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ fn add(rt: &Runtime) {
|
||||||
.map(FromStr::from_str)
|
.map(FromStr::from_str)
|
||||||
.map(|elem| {
|
.map(|elem| {
|
||||||
elem.or_else(|_| Err(Error::from(err_msg("Error while converting number"))))
|
elem.or_else(|_| Err(Error::from(err_msg("Error while converting number"))))
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
})
|
})
|
||||||
.collect::<Vec<i64>>();
|
.collect::<Vec<i64>>();
|
||||||
|
|
||||||
|
@ -125,18 +125,18 @@ fn add(rt: &Runtime) {
|
||||||
};
|
};
|
||||||
|
|
||||||
rt.ids::<::ui::PathProvider>()
|
rt.ids::<::ui::PathProvider>()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.for_each(|id| {
|
.for_each(|id| {
|
||||||
rt.store()
|
rt.store()
|
||||||
.get(id.clone())
|
.get(id.clone())
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.unwrap_or_else(|| { // if we have Ok(None)
|
.unwrap_or_else(|| { // if we have Ok(None)
|
||||||
error!("No such entry: {}", id);
|
error!("No such entry: {}", id);
|
||||||
exit(1)
|
exit(1)
|
||||||
})
|
})
|
||||||
.set_coordinates(c.clone())
|
.set_coordinates(c.clone())
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let _ = rt.report_touched(&id).unwrap_or_exit();
|
let _ = rt.report_touched(&id).unwrap_or_exit();
|
||||||
});
|
});
|
||||||
|
@ -150,24 +150,24 @@ fn remove(rt: &Runtime) {
|
||||||
.is_present("print-removed"); // safed by main()
|
.is_present("print-removed"); // safed by main()
|
||||||
|
|
||||||
rt.ids::<::ui::PathProvider>()
|
rt.ids::<::ui::PathProvider>()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.for_each(|id| {
|
.for_each(|id| {
|
||||||
let removed_value = rt
|
let removed_value = rt
|
||||||
.store()
|
.store()
|
||||||
.get(id.clone())
|
.get(id.clone())
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.unwrap_or_else(|| { // if we have Ok(None)
|
.unwrap_or_else(|| { // if we have Ok(None)
|
||||||
error!("No such entry: {}", id);
|
error!("No such entry: {}", id);
|
||||||
exit(1)
|
exit(1)
|
||||||
})
|
})
|
||||||
.remove_coordinates()
|
.remove_coordinates()
|
||||||
.map_err_trace_exit_unwrap(1) // The delete action failed
|
.map_err_trace_exit_unwrap() // The delete action failed
|
||||||
.unwrap_or_else(|| { // if we have Ok(None)
|
.unwrap_or_else(|| { // if we have Ok(None)
|
||||||
error!("Entry had no coordinates: {}", id);
|
error!("Entry had no coordinates: {}", id);
|
||||||
exit(1)
|
exit(1)
|
||||||
})
|
})
|
||||||
.map_err_trace_exit_unwrap(1); // The parsing of the deleted values failed
|
.map_err_trace_exit_unwrap(); // The parsing of the deleted values failed
|
||||||
|
|
||||||
if print_removed {
|
if print_removed {
|
||||||
let _ = writeln!(rt.stdout(), "{}", removed_value).to_exit_code().unwrap_or_exit();
|
let _ = writeln!(rt.stdout(), "{}", removed_value).to_exit_code().unwrap_or_exit();
|
||||||
|
@ -180,19 +180,19 @@ fn remove(rt: &Runtime) {
|
||||||
fn get(rt: &Runtime) {
|
fn get(rt: &Runtime) {
|
||||||
let mut stdout = rt.stdout();
|
let mut stdout = rt.stdout();
|
||||||
rt.ids::<::ui::PathProvider>()
|
rt.ids::<::ui::PathProvider>()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.for_each(|id| {
|
.for_each(|id| {
|
||||||
let value = rt
|
let value = rt
|
||||||
.store()
|
.store()
|
||||||
.get(id.clone())
|
.get(id.clone())
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.unwrap_or_else(|| { // if we have Ok(None)
|
.unwrap_or_else(|| { // if we have Ok(None)
|
||||||
error!("No such entry: {}", id);
|
error!("No such entry: {}", id);
|
||||||
exit(1)
|
exit(1)
|
||||||
})
|
})
|
||||||
.get_coordinates()
|
.get_coordinates()
|
||||||
.map_err_trace_exit_unwrap(1) // The get action failed
|
.map_err_trace_exit_unwrap() // The get action failed
|
||||||
.unwrap_or_else(|| { // if we have Ok(None)
|
.unwrap_or_else(|| { // if we have Ok(None)
|
||||||
error!("Entry has no coordinates: {}", id);
|
error!("Entry has no coordinates: {}", id);
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
|
@ -112,7 +112,7 @@ impl IdPathProvider for PathProvider {
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
.map(|pb| pb.into_storeid())
|
.map(|pb| pb.into_storeid())
|
||||||
.collect::<Result<Vec<_>, _>>()
|
.collect::<Result<Vec<_>, _>>()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
},
|
},
|
||||||
|
|
||||||
("remove", Some(subm)) => {
|
("remove", Some(subm)) => {
|
||||||
|
@ -126,7 +126,7 @@ impl IdPathProvider for PathProvider {
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
.map(|pb| pb.into_storeid())
|
.map(|pb| pb.into_storeid())
|
||||||
.collect::<Result<Vec<_>, _>>()
|
.collect::<Result<Vec<_>, _>>()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
},
|
},
|
||||||
|
|
||||||
("get", Some(subm)) => {
|
("get", Some(subm)) => {
|
||||||
|
@ -140,7 +140,7 @@ impl IdPathProvider for PathProvider {
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
.map(|pb| pb.into_storeid())
|
.map(|pb| pb.into_storeid())
|
||||||
.collect::<Result<Vec<_>, _>>()
|
.collect::<Result<Vec<_>, _>>()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
},
|
},
|
||||||
|
|
||||||
(other, _) => {
|
(other, _) => {
|
||||||
|
|
|
@ -87,9 +87,9 @@ fn main() {
|
||||||
let overall_count = rt
|
let overall_count = rt
|
||||||
.store()
|
.store()
|
||||||
.entries()
|
.entries()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.into_get_iter()
|
.into_get_iter()
|
||||||
.filter_map(|res| res.map_err_trace_exit_unwrap(1))
|
.filter_map(|res| res.map_err_trace_exit_unwrap())
|
||||||
.filter(|entry| pattern.is_match(entry.get_content()))
|
.filter(|entry| pattern.is_match(entry.get_content()))
|
||||||
.map(|entry| show(&rt, &entry, &pattern, &opts, &mut count))
|
.map(|entry| show(&rt, &entry, &pattern, &opts, &mut count))
|
||||||
.count();
|
.count();
|
||||||
|
|
|
@ -405,7 +405,7 @@ pub mod header_filter_lang {
|
||||||
.get_header()
|
.get_header()
|
||||||
.read(selector_str)
|
.read(selector_str)
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.map(|value| {
|
.map(|value| {
|
||||||
let comp = Comparator(&self.compare_operator, &self.compare_value);
|
let comp = Comparator(&self.compare_operator, &self.compare_value);
|
||||||
let val = match self.selector.function() {
|
let val = match self.selector.function() {
|
||||||
|
|
|
@ -93,14 +93,14 @@ fn main() {
|
||||||
|
|
||||||
let iterator = if rt.ids_from_stdin() {
|
let iterator = if rt.ids_from_stdin() {
|
||||||
debug!("Fetching IDs from stdin...");
|
debug!("Fetching IDs from stdin...");
|
||||||
let ids = rt.ids::<::ui::PathProvider>().map_err_trace_exit_unwrap(1);
|
let ids = rt.ids::<::ui::PathProvider>().map_err_trace_exit_unwrap();
|
||||||
Box::new(ids.into_iter().map(Ok))
|
Box::new(ids.into_iter().map(Ok))
|
||||||
as Box<Iterator<Item = Result<StoreId, _>>>
|
as Box<Iterator<Item = Result<StoreId, _>>>
|
||||||
} else {
|
} else {
|
||||||
Box::new(rt.store().entries().map_err_trace_exit_unwrap(1))
|
Box::new(rt.store().entries().map_err_trace_exit_unwrap())
|
||||||
as Box<Iterator<Item = Result<StoreId, _>>>
|
as Box<Iterator<Item = Result<StoreId, _>>>
|
||||||
}
|
}
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.filter(|id| collection_filter.filter(id))
|
.filter(|id| collection_filter.filter(id))
|
||||||
.filter(|id| match query_filter.as_ref() {
|
.filter(|id| match query_filter.as_ref() {
|
||||||
None => true,
|
None => true,
|
||||||
|
@ -108,7 +108,7 @@ fn main() {
|
||||||
let entry = rt
|
let entry = rt
|
||||||
.store()
|
.store()
|
||||||
.get(id.clone())
|
.get(id.clone())
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
error!("Tried to get '{}', but it does not exist!", id);
|
error!("Tried to get '{}', but it does not exist!", id);
|
||||||
exit(1)
|
exit(1)
|
||||||
|
@ -127,10 +127,10 @@ fn main() {
|
||||||
trace!("Got output: {:?}", stdout);
|
trace!("Got output: {:?}", stdout);
|
||||||
|
|
||||||
iterator.for_each(|id| {
|
iterator.for_each(|id| {
|
||||||
let _ = rt.report_touched(&id).unwrap_or_exit(); // .map_err_trace_exit_unwrap(1);
|
let _ = rt.report_touched(&id).unwrap_or_exit(); // .map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
if !rt.output_is_pipe() {
|
if !rt.output_is_pipe() {
|
||||||
let id = id.to_str().map_err_trace_exit_unwrap(1);
|
let id = id.to_str().map_err_trace_exit_unwrap();
|
||||||
trace!("Writing to {:?}", stdout);
|
trace!("Writing to {:?}", stdout);
|
||||||
writeln!(stdout, "{}", id)
|
writeln!(stdout, "{}", id)
|
||||||
.to_exit_code()
|
.to_exit_code()
|
||||||
|
|
|
@ -111,7 +111,7 @@ fn main() {
|
||||||
other => {
|
other => {
|
||||||
debug!("Unknown command");
|
debug!("Unknown command");
|
||||||
let _ = rt.handle_unknown_subcommand("imag-link", other, rt.cli())
|
let _ = rt.handle_unknown_subcommand("imag-link", other, rt.cli())
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.code()
|
.code()
|
||||||
.map(::std::process::exit);
|
.map(::std::process::exit);
|
||||||
},
|
},
|
||||||
|
@ -125,7 +125,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.ok_or_else(|| Error::from(err_msg("No commandline call".to_owned())))
|
.ok_or_else(|| Error::from(err_msg("No commandline call".to_owned())))
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_entry_by_name<'a>(rt: &'a Runtime, name: &str) -> Result<Option<FileLockEntry<'a>>> {
|
fn get_entry_by_name<'a>(rt: &'a Runtime, name: &str) -> Result<Option<FileLockEntry<'a>>> {
|
||||||
|
@ -142,7 +142,7 @@ fn get_entry_by_name<'a>(rt: &'a Runtime, name: &str) -> Result<Option<FileLockE
|
||||||
fn link_from_to<'a, I>(rt: &'a Runtime, from: &'a str, to: I)
|
fn link_from_to<'a, I>(rt: &'a Runtime, from: &'a str, to: I)
|
||||||
where I: Iterator<Item = &'a str>
|
where I: Iterator<Item = &'a str>
|
||||||
{
|
{
|
||||||
let mut from_entry = match get_entry_by_name(rt, from).map_err_trace_exit_unwrap(1) {
|
let mut from_entry = match get_entry_by_name(rt, from).map_err_trace_exit_unwrap() {
|
||||||
Some(e) => e,
|
Some(e) => e,
|
||||||
None => {
|
None => {
|
||||||
debug!("No 'from' entry");
|
debug!("No 'from' entry");
|
||||||
|
@ -152,7 +152,7 @@ fn link_from_to<'a, I>(rt: &'a Runtime, from: &'a str, to: I)
|
||||||
|
|
||||||
for entry in to {
|
for entry in to {
|
||||||
debug!("Handling 'to' entry: {:?}", entry);
|
debug!("Handling 'to' entry: {:?}", entry);
|
||||||
if !rt.store().get(PathBuf::from(entry)).map_err_trace_exit_unwrap(1).is_some() {
|
if !rt.store().get(PathBuf::from(entry)).map_err_trace_exit_unwrap().is_some() {
|
||||||
debug!("Linking externally: {:?} -> {:?}", from, entry);
|
debug!("Linking externally: {:?} -> {:?}", from, entry);
|
||||||
let url = Url::parse(entry).unwrap_or_else(|e| {
|
let url = Url::parse(entry).unwrap_or_else(|e| {
|
||||||
error!("Error parsing URL: {:?}", e);
|
error!("Error parsing URL: {:?}", e);
|
||||||
|
@ -161,22 +161,22 @@ fn link_from_to<'a, I>(rt: &'a Runtime, from: &'a str, to: I)
|
||||||
|
|
||||||
let iter = from_entry
|
let iter = from_entry
|
||||||
.add_external_link(rt.store(), url)
|
.add_external_link(rt.store(), url)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.into_iter();
|
.into_iter();
|
||||||
|
|
||||||
let _ = rt.report_all_touched(iter).unwrap_or_exit();
|
let _ = rt.report_all_touched(iter).unwrap_or_exit();
|
||||||
} else {
|
} else {
|
||||||
debug!("Linking internally: {:?} -> {:?}", from, entry);
|
debug!("Linking internally: {:?} -> {:?}", from, entry);
|
||||||
|
|
||||||
let from_id = StoreId::new_baseless(PathBuf::from(from)).map_err_trace_exit_unwrap(1);
|
let from_id = StoreId::new_baseless(PathBuf::from(from)).map_err_trace_exit_unwrap();
|
||||||
let entr_id = StoreId::new_baseless(PathBuf::from(entry)).map_err_trace_exit_unwrap(1);
|
let entr_id = StoreId::new_baseless(PathBuf::from(entry)).map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
if from_id == entr_id {
|
if from_id == entr_id {
|
||||||
error!("Cannot link entry with itself. Exiting");
|
error!("Cannot link entry with itself. Exiting");
|
||||||
::std::process::exit(1)
|
::std::process::exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut to_entry = match rt.store().get(entr_id).map_err_trace_exit_unwrap(1) {
|
let mut to_entry = match rt.store().get(entr_id).map_err_trace_exit_unwrap() {
|
||||||
Some(e) => e,
|
Some(e) => e,
|
||||||
None => {
|
None => {
|
||||||
warn!("No 'to' entry: {}", entry);
|
warn!("No 'to' entry: {}", entry);
|
||||||
|
@ -185,7 +185,7 @@ fn link_from_to<'a, I>(rt: &'a Runtime, from: &'a str, to: I)
|
||||||
};
|
};
|
||||||
let _ = from_entry
|
let _ = from_entry
|
||||||
.add_internal_link(&mut to_entry)
|
.add_internal_link(&mut to_entry)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let _ = rt.report_touched(to_entry.get_location()).unwrap_or_exit();
|
let _ = rt.report_touched(to_entry.get_location()).unwrap_or_exit();
|
||||||
}
|
}
|
||||||
|
@ -206,21 +206,21 @@ fn remove_linking(rt: &Runtime) {
|
||||||
.map(|id| {
|
.map(|id| {
|
||||||
rt.store()
|
rt.store()
|
||||||
.get(id)
|
.get(id)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.ok_or_else(|| warn_exit("No 'from' entry", 1))
|
.ok_or_else(|| warn_exit("No 'from' entry", 1))
|
||||||
.unwrap() // safe by line above
|
.unwrap() // safe by line above
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
rt.ids::<::ui::PathProvider>()
|
rt.ids::<::ui::PathProvider>()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.for_each(|id| match rt.store().get(id.clone()) {
|
.for_each(|id| match rt.store().get(id.clone()) {
|
||||||
Err(e) => trace_error(&e),
|
Err(e) => trace_error(&e),
|
||||||
Ok(Some(mut to_entry)) => {
|
Ok(Some(mut to_entry)) => {
|
||||||
let _ = to_entry
|
let _ = to_entry
|
||||||
.remove_internal_link(&mut from)
|
.remove_internal_link(&mut from)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let _ = rt.report_touched(to_entry.get_location()).unwrap_or_exit();
|
let _ = rt.report_touched(to_entry.get_location()).unwrap_or_exit();
|
||||||
},
|
},
|
||||||
|
@ -236,7 +236,7 @@ fn remove_linking(rt: &Runtime) {
|
||||||
error!("Error parsing URL: {:?}", e);
|
error!("Error parsing URL: {:?}", e);
|
||||||
::std::process::exit(1);
|
::std::process::exit(1);
|
||||||
});
|
});
|
||||||
from.remove_external_link(rt.store(), url).map_err_trace_exit_unwrap(1);
|
from.remove_external_link(rt.store(), url).map_err_trace_exit_unwrap();
|
||||||
info!("Ok: {}", id);
|
info!("Ok: {}", id);
|
||||||
} else {
|
} else {
|
||||||
warn!("Entry not found: {:?}", id);
|
warn!("Entry not found: {:?}", id);
|
||||||
|
@ -248,16 +248,16 @@ fn remove_linking(rt: &Runtime) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unlink(rt: &Runtime) {
|
fn unlink(rt: &Runtime) {
|
||||||
rt.ids::<::ui::PathProvider>().map_err_trace_exit_unwrap(1).into_iter().for_each(|id| {
|
rt.ids::<::ui::PathProvider>().map_err_trace_exit_unwrap().into_iter().for_each(|id| {
|
||||||
rt.store()
|
rt.store()
|
||||||
.get(id.clone())
|
.get(id.clone())
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
warn!("No entry for {}", id);
|
warn!("No entry for {}", id);
|
||||||
::std::process::exit(1)
|
::std::process::exit(1)
|
||||||
})
|
})
|
||||||
.unlink(rt.store())
|
.unlink(rt.store())
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let _ = rt.report_touched(&id).unwrap_or_exit();
|
let _ = rt.report_touched(&id).unwrap_or_exit();
|
||||||
});
|
});
|
||||||
|
@ -274,10 +274,10 @@ fn list_linkings(rt: &Runtime) {
|
||||||
let mut tab = ::prettytable::Table::new();
|
let mut tab = ::prettytable::Table::new();
|
||||||
tab.set_titles(row!["#", "Link"]);
|
tab.set_titles(row!["#", "Link"]);
|
||||||
|
|
||||||
rt.ids::<::ui::PathProvider>().map_err_trace_exit_unwrap(1).into_iter().for_each(|id| {
|
rt.ids::<::ui::PathProvider>().map_err_trace_exit_unwrap().into_iter().for_each(|id| {
|
||||||
match rt.store().get(id.clone()) {
|
match rt.store().get(id.clone()) {
|
||||||
Ok(Some(entry)) => {
|
Ok(Some(entry)) => {
|
||||||
for (i, link) in entry.get_internal_links().map_err_trace_exit_unwrap(1).enumerate() {
|
for (i, link) in entry.get_internal_links().map_err_trace_exit_unwrap().enumerate() {
|
||||||
let link = link
|
let link = link
|
||||||
.to_str()
|
.to_str()
|
||||||
.map_warn_err(|e| format!("Failed to convert StoreId to string: {:?}", e))
|
.map_warn_err(|e| format!("Failed to convert StoreId to string: {:?}", e))
|
||||||
|
@ -296,11 +296,11 @@ fn list_linkings(rt: &Runtime) {
|
||||||
|
|
||||||
if list_externals {
|
if list_externals {
|
||||||
entry.get_external_links(rt.store())
|
entry.get_external_links(rt.store())
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.for_each(|(i, link)| {
|
.for_each(|(i, link)| {
|
||||||
let link = link
|
let link = link
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.into_string();
|
.into_string();
|
||||||
|
|
||||||
if list_plain {
|
if list_plain {
|
||||||
|
|
|
@ -26,7 +26,6 @@ use libimagstore::storeid::IntoStoreId;
|
||||||
use libimagrt::runtime::IdPathProvider;
|
use libimagrt::runtime::IdPathProvider;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
|
|
||||||
|
|
||||||
pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
|
pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
|
||||||
app
|
app
|
||||||
.subcommand(SubCommand::with_name("remove")
|
.subcommand(SubCommand::with_name("remove")
|
||||||
|
@ -131,7 +130,7 @@ impl IdPathProvider for PathProvider {
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
.map(|pb| pb.into_storeid())
|
.map(|pb| pb.into_storeid())
|
||||||
.collect::<Result<Vec<_>, _>>()
|
.collect::<Result<Vec<_>, _>>()
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
Some(to)
|
Some(to)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -147,7 +146,7 @@ impl IdPathProvider for PathProvider {
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
.map(|pb| pb.into_storeid())
|
.map(|pb| pb.into_storeid())
|
||||||
.collect::<Result<Vec<_>, _>>()
|
.collect::<Result<Vec<_>, _>>()
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
Some(ids)
|
Some(ids)
|
||||||
},
|
},
|
||||||
|
@ -164,7 +163,7 @@ impl IdPathProvider for PathProvider {
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
.map(|pb| pb.into_storeid())
|
.map(|pb| pb.into_storeid())
|
||||||
.collect::<Result<Vec<_>, _>>()
|
.collect::<Result<Vec<_>, _>>()
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
Some(ids)
|
Some(ids)
|
||||||
},
|
},
|
||||||
|
@ -175,7 +174,7 @@ impl IdPathProvider for PathProvider {
|
||||||
ids.unwrap_or_else(|| {
|
ids.unwrap_or_else(|| {
|
||||||
matches.values_of("to")
|
matches.values_of("to")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.map(|s| PathBuf::from(s).into_storeid().map_err_trace_exit_unwrap(1))
|
.map(|s| PathBuf::from(s).into_storeid().map_err_trace_exit_unwrap())
|
||||||
.collect()
|
.collect()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ fn main() {
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
.map(StoreId::new_baseless)
|
.map(StoreId::new_baseless)
|
||||||
.unwrap() // unwrap safe by clap
|
.unwrap() // unwrap safe by clap
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let destname = rt
|
let destname = rt
|
||||||
.cli()
|
.cli()
|
||||||
|
@ -82,22 +82,22 @@ fn main() {
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
.map(StoreId::new_baseless)
|
.map(StoreId::new_baseless)
|
||||||
.unwrap() // unwrap safe by clap
|
.unwrap() // unwrap safe by clap
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
// remove links to entry, and re-add them later
|
// remove links to entry, and re-add them later
|
||||||
let mut linked_entries = {
|
let mut linked_entries = {
|
||||||
rt.store()
|
rt.store()
|
||||||
.get(sourcename.clone())
|
.get(sourcename.clone())
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
error!("Funny things happened: Entry moved to destination did not fail, but entry does not exist");
|
error!("Funny things happened: Entry moved to destination did not fail, but entry does not exist");
|
||||||
exit(1)
|
exit(1)
|
||||||
})
|
})
|
||||||
.get_internal_links()
|
.get_internal_links()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.map(|link| Ok(link.get_store_id().clone()) as Result<_, _>)
|
.map(|link| Ok(link.get_store_id().clone()) as Result<_, _>)
|
||||||
.into_get_iter(rt.store())
|
.into_get_iter(rt.store())
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.map(|e| {
|
.map(|e| {
|
||||||
e.unwrap_or_else(|| {
|
e.unwrap_or_else(|| {
|
||||||
error!("Linked entry does not exist");
|
error!("Linked entry does not exist");
|
||||||
|
@ -111,14 +111,14 @@ fn main() {
|
||||||
let mut entry = rt
|
let mut entry = rt
|
||||||
.store()
|
.store()
|
||||||
.get(sourcename.clone())
|
.get(sourcename.clone())
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
error!("Source Entry does not exist");
|
error!("Source Entry does not exist");
|
||||||
exit(1)
|
exit(1)
|
||||||
});
|
});
|
||||||
|
|
||||||
for link in linked_entries.iter_mut() {
|
for link in linked_entries.iter_mut() {
|
||||||
let _ = entry.remove_internal_link(link).map_err_trace_exit_unwrap(1);
|
let _ = entry.remove_internal_link(link).map_err_trace_exit_unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ fn main() {
|
||||||
relink(rt.store(), sourcename.clone(), &mut linked_entries);
|
relink(rt.store(), sourcename.clone(), &mut linked_entries);
|
||||||
e
|
e
|
||||||
})
|
})
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let _ = rt.report_touched(&destname).unwrap_or_exit();
|
let _ = rt.report_touched(&destname).unwrap_or_exit();
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ fn main() {
|
||||||
fn relink<'a>(store: &'a Store, target: StoreId, linked_entries: &mut Vec<FileLockEntry<'a>>) {
|
fn relink<'a>(store: &'a Store, target: StoreId, linked_entries: &mut Vec<FileLockEntry<'a>>) {
|
||||||
let mut entry = store
|
let mut entry = store
|
||||||
.get(target)
|
.get(target)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
error!("Funny things happened: Entry moved to destination did not fail, but entry does not exist");
|
error!("Funny things happened: Entry moved to destination did not fail, but entry does not exist");
|
||||||
exit(1)
|
exit(1)
|
||||||
|
@ -151,6 +151,6 @@ fn relink<'a>(store: &'a Store, target: StoreId, linked_entries: &mut Vec<FileLo
|
||||||
|
|
||||||
|
|
||||||
for mut link in linked_entries {
|
for mut link in linked_entries {
|
||||||
let _ = entry.add_internal_link(&mut link).map_err_trace_exit_unwrap(1);
|
let _ = entry.add_internal_link(&mut link).map_err_trace_exit_unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,7 @@ use std::path::PathBuf;
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
use libimagrt::setup::generate_runtime_setup;
|
use libimagrt::setup::generate_runtime_setup;
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagstore::storeid::IntoStoreId;
|
use libimagstore::storeid::IntoStoreId;
|
||||||
|
@ -72,7 +73,7 @@ fn main() {
|
||||||
other => {
|
other => {
|
||||||
debug!("Unknown command");
|
debug!("Unknown command");
|
||||||
let _ = rt.handle_unknown_subcommand("imag-ref", other, rt.cli())
|
let _ = rt.handle_unknown_subcommand("imag-ref", other, rt.cli())
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.code()
|
.code()
|
||||||
.map(::std::process::exit);
|
.map(::std::process::exit);
|
||||||
},
|
},
|
||||||
|
@ -87,13 +88,13 @@ fn deref(rt: &Runtime) {
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
.unwrap() // saved by clap
|
.unwrap() // saved by clap
|
||||||
.into_storeid()
|
.into_storeid()
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
match rt.store().get(id.clone()).map_err_trace_exit_unwrap(1) {
|
match rt.store().get(id.clone()).map_err_trace_exit_unwrap() {
|
||||||
Some(entry) => {
|
Some(entry) => {
|
||||||
entry
|
entry
|
||||||
.get_path()
|
.get_path()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.to_str()
|
.to_str()
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
error!("Could not transform path into string!");
|
error!("Could not transform path into string!");
|
||||||
|
@ -121,7 +122,7 @@ fn remove(rt: &Runtime) {
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
.unwrap() // saved by clap
|
.unwrap() // saved by clap
|
||||||
.into_storeid()
|
.into_storeid()
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let mut input = rt.stdin().unwrap_or_else(|| {
|
let mut input = rt.stdin().unwrap_or_else(|| {
|
||||||
error!("No input stream. Cannot ask for permission");
|
error!("No input stream. Cannot ask for permission");
|
||||||
|
@ -130,13 +131,13 @@ fn remove(rt: &Runtime) {
|
||||||
|
|
||||||
let mut output = rt.stdout();
|
let mut output = rt.stdout();
|
||||||
|
|
||||||
match rt.store().get(id.clone()).map_err_trace_exit_unwrap(1) {
|
match rt.store().get(id.clone()).map_err_trace_exit_unwrap() {
|
||||||
Some(mut entry) => {
|
Some(mut entry) => {
|
||||||
if yes ||
|
if yes ||
|
||||||
ask_bool(&format!("Delete ref from entry '{}'", id), None, &mut input, &mut output)
|
ask_bool(&format!("Delete ref from entry '{}'", id), None, &mut input, &mut output)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
{
|
{
|
||||||
let _ = entry.remove_ref().map_err_trace_exit_unwrap(1);
|
let _ = entry.remove_ref().map_err_trace_exit_unwrap();
|
||||||
} else {
|
} else {
|
||||||
info!("Aborted");
|
info!("Aborted");
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ use libimagrt::runtime::Runtime;
|
||||||
use libimagstore::store::Entry;
|
use libimagstore::store::Entry;
|
||||||
use libimagstore::storeid::StoreId;
|
use libimagstore::storeid::StoreId;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
use libimagutil::debug_result::*;
|
use libimagutil::debug_result::*;
|
||||||
|
|
||||||
use util::build_toml_header;
|
use util::build_toml_header;
|
||||||
|
@ -44,7 +45,7 @@ pub fn create(rt: &Runtime) {
|
||||||
let path = scmd.value_of("path").unwrap();
|
let path = scmd.value_of("path").unwrap();
|
||||||
let path = PathBuf::from(path);
|
let path = PathBuf::from(path);
|
||||||
let store = Some(rt.store().path().clone());
|
let store = Some(rt.store().path().clone());
|
||||||
let path = StoreId::new(store, path).map_err_trace_exit_unwrap(1);
|
let path = StoreId::new(store, path).map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
debug!("path = {:?}", path);
|
debug!("path = {:?}", path);
|
||||||
|
|
||||||
|
@ -61,7 +62,7 @@ pub fn create(rt: &Runtime) {
|
||||||
create_with_content_and_header(rt, &path, String::new(),
|
create_with_content_and_header(rt, &path, String::new(),
|
||||||
Entry::default_header())
|
Entry::default_header())
|
||||||
}
|
}
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let _ = rt.report_touched(&path).unwrap_or_exit();
|
let _ = rt.report_touched(&path).unwrap_or_exit();
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,13 +29,13 @@ pub fn delete(rt: &Runtime) {
|
||||||
let id = scmd.value_of("id").unwrap(); // safe by clap
|
let id = scmd.value_of("id").unwrap(); // safe by clap
|
||||||
let path = PathBuf::from(id);
|
let path = PathBuf::from(id);
|
||||||
let store = Some(rt.store().path().clone());
|
let store = Some(rt.store().path().clone());
|
||||||
let path = StoreId::new(store, path).map_err_trace_exit_unwrap(1);
|
let path = StoreId::new(store, path).map_err_trace_exit_unwrap();
|
||||||
debug!("Deleting file at {:?}", id);
|
debug!("Deleting file at {:?}", id);
|
||||||
|
|
||||||
let _ = 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_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -21,6 +21,7 @@ use std::path::PathBuf;
|
||||||
|
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
use libimagstore::storeid::StoreId;
|
use libimagstore::storeid::StoreId;
|
||||||
|
|
||||||
use retrieve::print_entry;
|
use retrieve::print_entry;
|
||||||
|
@ -31,10 +32,10 @@ pub fn get(rt: &Runtime) {
|
||||||
let id = scmd.value_of("id").unwrap(); // safe by clap
|
let id = scmd.value_of("id").unwrap(); // safe by clap
|
||||||
let path = PathBuf::from(id);
|
let path = PathBuf::from(id);
|
||||||
let store = Some(rt.store().path().clone());
|
let store = Some(rt.store().path().clone());
|
||||||
let path = StoreId::new(store, path).map_err_trace_exit_unwrap(1);
|
let path = StoreId::new(store, path).map_err_trace_exit_unwrap();
|
||||||
debug!("path = {:?}", path);
|
debug!("path = {:?}", path);
|
||||||
|
|
||||||
let _ = match rt.store().get(path.clone()).map_err_trace_exit_unwrap(1) {
|
let _ = match rt.store().get(path.clone()).map_err_trace_exit_unwrap() {
|
||||||
Some(entry) => {
|
Some(entry) => {
|
||||||
print_entry(rt, scmd, entry);
|
print_entry(rt, scmd, entry);
|
||||||
let _ = rt.report_touched(&path).unwrap_or_exit();
|
let _ = rt.report_touched(&path).unwrap_or_exit();
|
||||||
|
|
|
@ -94,7 +94,7 @@ fn main() {
|
||||||
other => {
|
other => {
|
||||||
debug!("Unknown command");
|
debug!("Unknown command");
|
||||||
let _ = rt.handle_unknown_subcommand("imag-store", other, rt.cli())
|
let _ = rt.handle_unknown_subcommand("imag-store", other, rt.cli())
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.code()
|
.code()
|
||||||
.map(::std::process::exit);
|
.map(::std::process::exit);
|
||||||
},
|
},
|
||||||
|
|
|
@ -38,7 +38,7 @@ pub fn retrieve(rt: &Runtime) {
|
||||||
let id = scmd.value_of("id").unwrap();
|
let id = scmd.value_of("id").unwrap();
|
||||||
let path = PathBuf::from(id);
|
let path = PathBuf::from(id);
|
||||||
let store = Some(rt.store().path().clone());
|
let store = Some(rt.store().path().clone());
|
||||||
let path = StoreId::new(store, path).map_err_trace_exit_unwrap(1);
|
let path = StoreId::new(store, path).map_err_trace_exit_unwrap();
|
||||||
debug!("path = {:?}", path);
|
debug!("path = {:?}", path);
|
||||||
|
|
||||||
rt.store()
|
rt.store()
|
||||||
|
@ -46,7 +46,7 @@ pub fn retrieve(rt: &Runtime) {
|
||||||
.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_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let _ = rt.report_touched(&path).unwrap_or_exit();
|
let _ = rt.report_touched(&path).unwrap_or_exit();
|
||||||
});
|
});
|
||||||
|
@ -55,7 +55,7 @@ pub fn retrieve(rt: &Runtime) {
|
||||||
pub fn print_entry(rt: &Runtime, scmd: &ArgMatches, e: FileLockEntry) {
|
pub fn print_entry(rt: &Runtime, scmd: &ArgMatches, e: FileLockEntry) {
|
||||||
if do_print_raw(scmd) {
|
if do_print_raw(scmd) {
|
||||||
debug!("Printing raw content...");
|
debug!("Printing raw content...");
|
||||||
let _ = writeln!(rt.stdout(), "{}", e.to_str().map_err_trace_exit_unwrap(1))
|
let _ = writeln!(rt.stdout(), "{}", e.to_str().map_err_trace_exit_unwrap())
|
||||||
.to_exit_code()
|
.to_exit_code()
|
||||||
.unwrap_or_exit();
|
.unwrap_or_exit();
|
||||||
} else if do_filter(scmd) {
|
} else if do_filter(scmd) {
|
||||||
|
|
|
@ -22,6 +22,7 @@ use std::path::PathBuf;
|
||||||
|
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
use libimagstore::storeid::StoreId;
|
use libimagstore::storeid::StoreId;
|
||||||
|
|
||||||
use util::build_toml_header;
|
use util::build_toml_header;
|
||||||
|
@ -31,7 +32,7 @@ pub fn update(rt: &Runtime) {
|
||||||
let id = scmd.value_of("id").unwrap(); // Safe by clap
|
let id = scmd.value_of("id").unwrap(); // Safe by clap
|
||||||
let path = PathBuf::from(id);
|
let path = PathBuf::from(id);
|
||||||
let store = Some(rt.store().path().clone());
|
let store = Some(rt.store().path().clone());
|
||||||
let path = StoreId::new(store, path).map_err_trace_exit_unwrap(1);
|
let path = StoreId::new(store, path).map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let _ = rt.store()
|
let _ = rt.store()
|
||||||
.retrieve(path)
|
.retrieve(path)
|
||||||
|
|
|
@ -22,6 +22,7 @@ use std::ops::Deref;
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagutil::warn_exit::warn_exit;
|
use libimagutil::warn_exit::warn_exit;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
use libimagerror::iter::TraceIterator;
|
use libimagerror::iter::TraceIterator;
|
||||||
|
|
||||||
/// Verify the store.
|
/// Verify the store.
|
||||||
|
@ -33,9 +34,9 @@ pub fn verify(rt: &Runtime) {
|
||||||
let result = rt
|
let result = rt
|
||||||
.store()
|
.store()
|
||||||
.entries()
|
.entries()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.into_get_iter()
|
.into_get_iter()
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.filter_map(|x| x)
|
.filter_map(|x| x)
|
||||||
.all(|fle| {
|
.all(|fle| {
|
||||||
let p = fle.get_location();
|
let p = fle.get_location();
|
||||||
|
|
|
@ -84,7 +84,7 @@ fn main() {
|
||||||
"Direct interface to the store. Use with great care!",
|
"Direct interface to the store. Use with great care!",
|
||||||
build_ui);
|
build_ui);
|
||||||
|
|
||||||
let ids = rt.ids::<::ui::PathProvider>().map_err_trace_exit_unwrap(1);
|
let ids = rt.ids::<::ui::PathProvider>().map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
rt.cli()
|
rt.cli()
|
||||||
.subcommand_name()
|
.subcommand_name()
|
||||||
|
@ -107,7 +107,7 @@ fn main() {
|
||||||
other => {
|
other => {
|
||||||
debug!("Unknown command");
|
debug!("Unknown command");
|
||||||
let _ = rt.handle_unknown_subcommand("imag-tag", other, rt.cli())
|
let _ = rt.handle_unknown_subcommand("imag-tag", other, rt.cli())
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.code()
|
.code()
|
||||||
.map(::std::process::exit);
|
.map(::std::process::exit);
|
||||||
},
|
},
|
||||||
|
@ -161,7 +161,7 @@ fn alter(rt: &Runtime, path: StoreId, add: Option<Vec<Tag>>, rem: Option<Vec<Tag
|
||||||
}
|
}
|
||||||
|
|
||||||
fn list(path: StoreId, rt: &Runtime) {
|
fn list(path: StoreId, rt: &Runtime) {
|
||||||
let entry = match rt.store().get(path.clone()).map_err_trace_exit_unwrap(1) {
|
let entry = match rt.store().get(path.clone()).map_err_trace_exit_unwrap() {
|
||||||
Some(e) => e,
|
Some(e) => e,
|
||||||
None => warn_exit("No entry found.", 1),
|
None => warn_exit("No entry found.", 1),
|
||||||
};
|
};
|
||||||
|
@ -178,7 +178,7 @@ fn list(path: StoreId, rt: &Runtime) {
|
||||||
comm_out = true;
|
comm_out = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
let tags = entry.get_tags().map_err_trace_exit_unwrap(1);
|
let tags = entry.get_tags().map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
if json_out {
|
if json_out {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
|
|
|
@ -108,7 +108,7 @@ impl IdPathProvider for PathProvider {
|
||||||
fn get_ids(matches: &ArgMatches) -> Vec<StoreId> {
|
fn get_ids(matches: &ArgMatches) -> Vec<StoreId> {
|
||||||
matches.values_of("id")
|
matches.values_of("id")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.map(|s| PathBuf::from(s).into_storeid().map_err_trace_exit_unwrap(1))
|
.map(|s| PathBuf::from(s).into_storeid().map_err_trace_exit_unwrap())
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,15 +83,15 @@ fn main() {
|
||||||
let view_header = rt.cli().is_present("view-header");
|
let view_header = rt.cli().is_present("view-header");
|
||||||
let hide_content = rt.cli().is_present("not-view-content");
|
let hide_content = rt.cli().is_present("not-view-content");
|
||||||
let entries = rt.ids::<::ui::PathProvider>()
|
let entries = rt.ids::<::ui::PathProvider>()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(Ok)
|
.map(Ok)
|
||||||
.into_get_iter(rt.store())
|
.into_get_iter(rt.store())
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.map(|e| {
|
.map(|e| {
|
||||||
e.ok_or_else(|| err_msg("Entry not found"))
|
e.ok_or_else(|| err_msg("Entry not found"))
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
});
|
});
|
||||||
|
|
||||||
if rt.cli().is_present("in") {
|
if rt.cli().is_present("in") {
|
||||||
|
@ -108,19 +108,19 @@ fn main() {
|
||||||
.cli()
|
.cli()
|
||||||
.value_of("in")
|
.value_of("in")
|
||||||
.ok_or_else(|| Error::from(err_msg("No viewer given")))
|
.ok_or_else(|| Error::from(err_msg("No viewer given")))
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let config = rt
|
let config = rt
|
||||||
.config()
|
.config()
|
||||||
.ok_or_else(|| Error::from(err_msg("No configuration, cannot continue")))
|
.ok_or_else(|| Error::from(err_msg("No configuration, cannot continue")))
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let query = format!("view.viewers.{}", viewer);
|
let query = format!("view.viewers.{}", viewer);
|
||||||
|
|
||||||
let viewer_template = config
|
let viewer_template = config
|
||||||
.read_string(&query)
|
.read_string(&query)
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
error!("Cannot find '{}' in config", query);
|
error!("Cannot find '{}' in config", query);
|
||||||
exit(1)
|
exit(1)
|
||||||
|
@ -132,7 +132,7 @@ fn main() {
|
||||||
let _ = handlebars
|
let _ = handlebars
|
||||||
.register_template_string("template", viewer_template)
|
.register_template_string("template", viewer_template)
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let mut data = BTreeMap::new();
|
let mut data = BTreeMap::new();
|
||||||
|
|
||||||
|
@ -147,12 +147,12 @@ fn main() {
|
||||||
let call = handlebars
|
let call = handlebars
|
||||||
.render("template", &data)
|
.render("template", &data)
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
let mut elems = call.split_whitespace();
|
let mut elems = call.split_whitespace();
|
||||||
let command_string = elems
|
let command_string = elems
|
||||||
.next()
|
.next()
|
||||||
.ok_or_else(|| Error::from(err_msg("No command")))
|
.ok_or_else(|| Error::from(err_msg("No command")))
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
let mut cmd = Command::new(command_string);
|
let mut cmd = Command::new(command_string);
|
||||||
|
|
||||||
for arg in elems {
|
for arg in elems {
|
||||||
|
@ -167,7 +167,7 @@ fn main() {
|
||||||
if !command
|
if !command
|
||||||
.status()
|
.status()
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.success()
|
.success()
|
||||||
{
|
{
|
||||||
exit(1)
|
exit(1)
|
||||||
|
@ -206,7 +206,7 @@ fn main() {
|
||||||
|
|
||||||
viewer
|
viewer
|
||||||
.view_entry(&entry, &mut outlock)
|
.view_entry(&entry, &mut outlock)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
rt.report_touched(entry.get_location()).unwrap_or_exit();
|
rt.report_touched(entry.get_location()).unwrap_or_exit();
|
||||||
});
|
});
|
||||||
|
@ -240,7 +240,7 @@ fn main() {
|
||||||
|
|
||||||
viewer
|
viewer
|
||||||
.view_entry(&entry, &mut outlock)
|
.view_entry(&entry, &mut outlock)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
rt.report_touched(entry.get_location()).unwrap_or_exit();
|
rt.report_touched(entry.get_location()).unwrap_or_exit();
|
||||||
});
|
});
|
||||||
|
@ -253,21 +253,21 @@ fn create_tempfile_for<'a>(entry: &FileLockEntry<'a>, view_header: bool, hide_co
|
||||||
{
|
{
|
||||||
let mut tmpfile = tempfile::NamedTempFile::new()
|
let mut tmpfile = tempfile::NamedTempFile::new()
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
if view_header {
|
if view_header {
|
||||||
let hdr = toml::ser::to_string_pretty(entry.get_header())
|
let hdr = toml::ser::to_string_pretty(entry.get_header())
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
let _ = tmpfile.write(format!("---\n{}---\n", hdr).as_bytes())
|
let _ = tmpfile.write(format!("---\n{}---\n", hdr).as_bytes())
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
if !hide_content {
|
if !hide_content {
|
||||||
let _ = tmpfile.write(entry.get_content().as_bytes())
|
let _ = tmpfile.write(entry.get_content().as_bytes())
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let file_path = tmpfile
|
let file_path = tmpfile
|
||||||
|
@ -275,7 +275,7 @@ fn create_tempfile_for<'a>(entry: &FileLockEntry<'a>, view_header: bool, hide_co
|
||||||
.to_str()
|
.to_str()
|
||||||
.map(String::from)
|
.map(String::from)
|
||||||
.ok_or_else(|| Error::from(err_msg("Cannot build path")))
|
.ok_or_else(|| Error::from(err_msg("Cannot build path")))
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
(tmpfile, file_path)
|
(tmpfile, file_path)
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,7 +93,7 @@ impl IdPathProvider for PathProvider {
|
||||||
fn get_ids(matches: &ArgMatches) -> Vec<StoreId> {
|
fn get_ids(matches: &ArgMatches) -> Vec<StoreId> {
|
||||||
matches.values_of("id")
|
matches.values_of("id")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.map(|s| PathBuf::from(s).into_storeid().map_err_trace_exit_unwrap(1))
|
.map(|s| PathBuf::from(s).into_storeid().map_err_trace_exit_unwrap())
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,7 @@ fn main() {
|
||||||
other => {
|
other => {
|
||||||
debug!("Unknown command");
|
debug!("Unknown command");
|
||||||
let _ = rt.handle_unknown_subcommand("imag-bookmark", other, rt.cli())
|
let _ = rt.handle_unknown_subcommand("imag-bookmark", other, rt.cli())
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.code()
|
.code()
|
||||||
.map(::std::process::exit);
|
.map(::std::process::exit);
|
||||||
},
|
},
|
||||||
|
@ -97,16 +97,16 @@ fn add(rt: &Runtime) {
|
||||||
let coll = get_collection_name(rt, "add", "collection");
|
let coll = get_collection_name(rt, "add", "collection");
|
||||||
|
|
||||||
let mut collection = BookmarkCollectionStore::get(rt.store(), &coll)
|
let mut collection = BookmarkCollectionStore::get(rt.store(), &coll)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.ok_or_else(|| format_err!("No bookmark collection '{}' found", coll))
|
.ok_or_else(|| format_err!("No bookmark collection '{}' found", coll))
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let _ = rt.report_touched(collection.get_location()).unwrap_or_exit();
|
let _ = rt.report_touched(collection.get_location()).unwrap_or_exit();
|
||||||
|
|
||||||
for url in scmd.values_of("urls").unwrap() { // unwrap saved by clap
|
for url in scmd.values_of("urls").unwrap() { // unwrap saved by clap
|
||||||
let new_ids = collection
|
let new_ids = collection
|
||||||
.add_link(rt.store(), BookmarkLink::from(url))
|
.add_link(rt.store(), BookmarkLink::from(url))
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let _ = rt.report_all_touched(new_ids.into_iter()).unwrap_or_exit();
|
let _ = rt.report_all_touched(new_ids.into_iter()).unwrap_or_exit();
|
||||||
}
|
}
|
||||||
|
@ -143,16 +143,16 @@ fn list(rt: &Runtime) {
|
||||||
let coll = get_collection_name(rt, "list", "collection");
|
let coll = get_collection_name(rt, "list", "collection");
|
||||||
|
|
||||||
let collection = BookmarkCollectionStore::get(rt.store(), &coll)
|
let collection = BookmarkCollectionStore::get(rt.store(), &coll)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.ok_or_else(|| format_err!("No bookmark collection '{}' found", coll))
|
.ok_or_else(|| format_err!("No bookmark collection '{}' found", coll))
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let _ = rt.report_touched(collection.get_location()).unwrap_or_exit();
|
let _ = rt.report_touched(collection.get_location()).unwrap_or_exit();
|
||||||
|
|
||||||
collection
|
collection
|
||||||
.links(rt.store())
|
.links(rt.store())
|
||||||
.map_dbg_str("Listing...")
|
.map_dbg_str("Listing...")
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.for_each(|(i, link)| match link {
|
.for_each(|(i, link)| match link {
|
||||||
|
@ -167,16 +167,16 @@ fn remove(rt: &Runtime) {
|
||||||
let coll = get_collection_name(rt, "list", "collection");
|
let coll = get_collection_name(rt, "list", "collection");
|
||||||
|
|
||||||
let mut collection = BookmarkCollectionStore::get(rt.store(), &coll)
|
let mut collection = BookmarkCollectionStore::get(rt.store(), &coll)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.ok_or_else(|| format_err!("No bookmark collection '{}' found", coll))
|
.ok_or_else(|| format_err!("No bookmark collection '{}' found", coll))
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let _ = rt.report_touched(collection.get_location()).unwrap_or_exit();
|
let _ = rt.report_touched(collection.get_location()).unwrap_or_exit();
|
||||||
|
|
||||||
for url in scmd.values_of("urls").unwrap() { // enforced by clap
|
for url in scmd.values_of("urls").unwrap() { // enforced by clap
|
||||||
let removed_links = collection
|
let removed_links = collection
|
||||||
.remove_link(rt.store(), BookmarkLink::from(url))
|
.remove_link(rt.store(), BookmarkLink::from(url))
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let _ = rt.report_all_touched(removed_links.into_iter()).unwrap_or_exit();
|
let _ = rt.report_all_touched(removed_links.into_iter()).unwrap_or_exit();
|
||||||
}
|
}
|
||||||
|
@ -198,7 +198,7 @@ fn get_collection_name(rt: &Runtime,
|
||||||
.map(|cfg| {
|
.map(|cfg| {
|
||||||
cfg.read_string("bookmark.default_collection")
|
cfg.read_string("bookmark.default_collection")
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
error!("Missing config: 'bookmark.default_collection'. Set or use commandline to specify.");
|
error!("Missing config: 'bookmark.default_collection'. Set or use commandline to specify.");
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
|
@ -51,6 +51,7 @@ use libimagcontact::store::ContactStore;
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
use libimagerror::trace::trace_error;
|
use libimagerror::trace::trace_error;
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
use libimagutil::warn_result::WarnResult;
|
use libimagutil::warn_result::WarnResult;
|
||||||
|
|
||||||
const TEMPLATE : &'static str = include_str!("../static/new-contact-template.toml");
|
const TEMPLATE : &'static str = include_str!("../static/new-contact-template.toml");
|
||||||
|
@ -75,7 +76,7 @@ mod test {
|
||||||
|
|
||||||
fn ask_continue(inputstream: &mut Read, outputstream: &mut Write) -> bool {
|
fn ask_continue(inputstream: &mut Read, outputstream: &mut Write) -> bool {
|
||||||
::libimaginteraction::ask::ask_bool("Edit tempfile", Some(true), inputstream, outputstream)
|
::libimaginteraction::ask::ask_bool("Edit tempfile", Some(true), inputstream, outputstream)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create(rt: &Runtime) {
|
pub fn create(rt: &Runtime) {
|
||||||
|
@ -122,7 +123,7 @@ pub fn create(rt: &Runtime) {
|
||||||
.open(fl.clone())
|
.open(fl.clone())
|
||||||
.map_warn_err_str("Cannot create/open destination File. Stopping.")
|
.map_warn_err_str("Cannot create/open destination File. Stopping.")
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let uuid_string = uuid
|
let uuid_string = uuid
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
|
@ -153,7 +154,7 @@ pub fn create(rt: &Runtime) {
|
||||||
loop {
|
loop {
|
||||||
::libimagentryedit::edit::edit_in_tmpfile(&rt, &mut template)
|
::libimagentryedit::edit::edit_in_tmpfile(&rt, &mut template)
|
||||||
.map_warn_err_str("Editing failed.")
|
.map_warn_err_str("Editing failed.")
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
if template == TEMPLATE || template.is_empty() {
|
if template == TEMPLATE || template.is_empty() {
|
||||||
error!("No (changed) content in tempfile. Not doing anything.");
|
error!("No (changed) content in tempfile. Not doing anything.");
|
||||||
|
@ -179,7 +180,7 @@ pub fn create(rt: &Runtime) {
|
||||||
Ok(Some(vcard)) => {
|
Ok(Some(vcard)) => {
|
||||||
if template == TEMPLATE || template.is_empty() {
|
if template == TEMPLATE || template.is_empty() {
|
||||||
if ::libimaginteraction::ask::ask_bool("Abort contact creating", Some(false), &mut input, &mut output)
|
if ::libimaginteraction::ask::ask_bool("Abort contact creating", Some(false), &mut input, &mut output)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
{
|
{
|
||||||
exit(1)
|
exit(1)
|
||||||
} else {
|
} else {
|
||||||
|
@ -191,7 +192,7 @@ pub fn create(rt: &Runtime) {
|
||||||
let _ = dest
|
let _ = dest
|
||||||
.write_all(&vcard_string.as_bytes())
|
.write_all(&vcard_string.as_bytes())
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -202,7 +203,7 @@ pub fn create(rt: &Runtime) {
|
||||||
if !scmd.is_present("dont-track") {
|
if !scmd.is_present("dont-track") {
|
||||||
let entry = rt.store()
|
let entry = rt.store()
|
||||||
.create_from_path(&location)
|
.create_from_path(&location)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let _ = rt.report_touched(entry.get_location()).unwrap_or_exit();
|
let _ = rt.report_touched(entry.get_location()).unwrap_or_exit();
|
||||||
|
|
||||||
|
@ -253,7 +254,7 @@ fn parse_toml_into_vcard(output: &mut Write, input: &mut Read, toml: Value, uuid
|
||||||
|
|
||||||
{ // parse nicknames
|
{ // parse nicknames
|
||||||
debug!("Parsing nicknames");
|
debug!("Parsing nicknames");
|
||||||
match toml.read("nickname").map_err(Error::from).map_err_trace_exit_unwrap(1) {
|
match toml.read("nickname").map_err(Error::from).map_err_trace_exit_unwrap() {
|
||||||
Some(&Value::Array(ref ary)) => {
|
Some(&Value::Array(ref ary)) => {
|
||||||
for (i, element) in ary.iter().enumerate() {
|
for (i, element) in ary.iter().enumerate() {
|
||||||
let nicktype = match read_str_from_toml(element, "type", false) {
|
let nicktype = match read_str_from_toml(element, "type", false) {
|
||||||
|
@ -323,7 +324,7 @@ fn parse_toml_into_vcard(output: &mut Write, input: &mut Read, toml: Value, uuid
|
||||||
|
|
||||||
{ // parse phone
|
{ // parse phone
|
||||||
debug!("Parse phone");
|
debug!("Parse phone");
|
||||||
match toml.read("person.phone").map_err(Error::from).map_err_trace_exit_unwrap(1) {
|
match toml.read("person.phone").map_err(Error::from).map_err_trace_exit_unwrap() {
|
||||||
Some(&Value::Array(ref ary)) => {
|
Some(&Value::Array(ref ary)) => {
|
||||||
for (i, element) in ary.iter().enumerate() {
|
for (i, element) in ary.iter().enumerate() {
|
||||||
let phonetype = match read_str_from_toml(element, "type", false) {
|
let phonetype = match read_str_from_toml(element, "type", false) {
|
||||||
|
@ -373,7 +374,7 @@ fn parse_toml_into_vcard(output: &mut Write, input: &mut Read, toml: Value, uuid
|
||||||
|
|
||||||
{ // parse address
|
{ // parse address
|
||||||
debug!("Parsing address");
|
debug!("Parsing address");
|
||||||
match toml.read("addresses").map_err(Error::from).map_err_trace_exit_unwrap(1) {
|
match toml.read("addresses").map_err(Error::from).map_err_trace_exit_unwrap() {
|
||||||
Some(&Value::Array(ref ary)) => {
|
Some(&Value::Array(ref ary)) => {
|
||||||
for (i, element) in ary.iter().enumerate() {
|
for (i, element) in ary.iter().enumerate() {
|
||||||
let adrtype = match read_str_from_toml(element, "type", false) {
|
let adrtype = match read_str_from_toml(element, "type", false) {
|
||||||
|
@ -428,7 +429,7 @@ fn parse_toml_into_vcard(output: &mut Write, input: &mut Read, toml: Value, uuid
|
||||||
|
|
||||||
{ // parse email
|
{ // parse email
|
||||||
debug!("Parsing email");
|
debug!("Parsing email");
|
||||||
match toml.read("person.email").map_err(Error::from).map_err_trace_exit_unwrap(1) {
|
match toml.read("person.email").map_err(Error::from).map_err_trace_exit_unwrap() {
|
||||||
Some(&Value::Array(ref ary)) => {
|
Some(&Value::Array(ref ary)) => {
|
||||||
for (i, element) in ary.iter().enumerate() {
|
for (i, element) in ary.iter().enumerate() {
|
||||||
let mailtype = match read_str_from_toml(element, "type", false) {
|
let mailtype = match read_str_from_toml(element, "type", false) {
|
||||||
|
|
|
@ -104,7 +104,7 @@ fn main() {
|
||||||
other => {
|
other => {
|
||||||
debug!("Unknown command");
|
debug!("Unknown command");
|
||||||
let _ = rt.handle_unknown_subcommand("imag-contact", other, rt.cli())
|
let _ = rt.handle_unknown_subcommand("imag-contact", other, rt.cli())
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.code()
|
.code()
|
||||||
.map(::std::process::exit);
|
.map(::std::process::exit);
|
||||||
},
|
},
|
||||||
|
@ -119,17 +119,17 @@ fn list(rt: &Runtime) {
|
||||||
let iterator = rt
|
let iterator = rt
|
||||||
.store()
|
.store()
|
||||||
.all_contacts()
|
.all_contacts()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.into_get_iter(rt.store())
|
.into_get_iter(rt.store())
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.map(|fle| fle.ok_or_else(|| Error::from(err_msg("StoreId not found".to_owned()))))
|
.map(|fle| fle.ok_or_else(|| Error::from(err_msg("StoreId not found".to_owned()))))
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.map(|fle| {
|
.map(|fle| {
|
||||||
let _ = rt.report_touched(fle.get_location()).unwrap_or_exit();
|
let _ = rt.report_touched(fle.get_location()).unwrap_or_exit();
|
||||||
fle
|
fle
|
||||||
})
|
})
|
||||||
.map(|e| e.deser())
|
.map(|e| e.deser())
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.enumerate();
|
.enumerate();
|
||||||
|
|
||||||
if scmd.is_present("json") {
|
if scmd.is_present("json") {
|
||||||
|
@ -148,7 +148,7 @@ fn list(rt: &Runtime) {
|
||||||
iterator
|
iterator
|
||||||
.map(|(i, dvcard)| build_data_object_for_handlebars(i, &dvcard))
|
.map(|(i, dvcard)| build_data_object_for_handlebars(i, &dvcard))
|
||||||
.map(|data| list_format.render("format", &data).map_err(Error::from))
|
.map(|data| list_format.render("format", &data).map_err(Error::from))
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.for_each(|s| {
|
.for_each(|s| {
|
||||||
writeln!(output, "{}", s).to_exit_code().unwrap_or_exit()
|
writeln!(output, "{}", s).to_exit_code().unwrap_or_exit()
|
||||||
});
|
});
|
||||||
|
@ -168,21 +168,21 @@ fn import(rt: &Runtime) {
|
||||||
let entry = rt
|
let entry = rt
|
||||||
.store()
|
.store()
|
||||||
.retrieve_from_path(&path)
|
.retrieve_from_path(&path)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let _ = rt.report_touched(entry.get_location()).unwrap_or_exit();
|
let _ = rt.report_touched(entry.get_location()).unwrap_or_exit();
|
||||||
} else if path.is_dir() {
|
} else if path.is_dir() {
|
||||||
for entry in WalkDir::new(path).min_depth(1).into_iter() {
|
for entry in WalkDir::new(path).min_depth(1).into_iter() {
|
||||||
let entry = entry
|
let entry = entry
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
if entry.file_type().is_file() {
|
if entry.file_type().is_file() {
|
||||||
let pb = PathBuf::from(entry.path());
|
let pb = PathBuf::from(entry.path());
|
||||||
let fle = rt
|
let fle = rt
|
||||||
.store()
|
.store()
|
||||||
.retrieve_from_path(&pb)
|
.retrieve_from_path(&pb)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let _ = rt.report_touched(fle.get_location()).unwrap_or_exit();
|
let _ = rt.report_touched(fle.get_location()).unwrap_or_exit();
|
||||||
info!("Imported: {}", entry.path().to_str().unwrap_or("<non UTF-8 path>"));
|
info!("Imported: {}", entry.path().to_str().unwrap_or("<non UTF-8 path>"));
|
||||||
|
@ -205,15 +205,15 @@ fn show(rt: &Runtime) {
|
||||||
|
|
||||||
rt.store()
|
rt.store()
|
||||||
.all_contacts()
|
.all_contacts()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.into_get_iter(rt.store())
|
.into_get_iter(rt.store())
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.map(|o| o.unwrap_or_else(|| {
|
.map(|o| o.unwrap_or_else(|| {
|
||||||
error!("Failed to get entry");
|
error!("Failed to get entry");
|
||||||
exit(1)
|
exit(1)
|
||||||
}))
|
}))
|
||||||
.filter_map(|entry| {
|
.filter_map(|entry| {
|
||||||
let deser = entry.deser().map_err_trace_exit_unwrap(1);
|
let deser = entry.deser().map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
if deser.uid()
|
if deser.uid()
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
|
@ -236,7 +236,7 @@ fn show(rt: &Runtime) {
|
||||||
let s = show_format
|
let s = show_format
|
||||||
.render("format", &data)
|
.render("format", &data)
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
let _ = writeln!(outlock, "{}", s).to_exit_code().unwrap_or_exit();
|
let _ = writeln!(outlock, "{}", s).to_exit_code().unwrap_or_exit();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -256,10 +256,10 @@ fn find(rt: &Runtime) {
|
||||||
let iterator = rt
|
let iterator = rt
|
||||||
.store()
|
.store()
|
||||||
.all_contacts()
|
.all_contacts()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.into_get_iter(rt.store())
|
.into_get_iter(rt.store())
|
||||||
.map(|el| {
|
.map(|el| {
|
||||||
el.map_err_trace_exit_unwrap(1)
|
el.map_err_trace_exit_unwrap()
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
error!("Could not get StoreId from Store::all_contacts(). This is a BUG!");
|
error!("Could not get StoreId from Store::all_contacts(). This is a BUG!");
|
||||||
::std::process::exit(1)
|
::std::process::exit(1)
|
||||||
|
@ -267,7 +267,7 @@ fn find(rt: &Runtime) {
|
||||||
.unwrap() // safed above
|
.unwrap() // safed above
|
||||||
})
|
})
|
||||||
.filter_map(|entry| {
|
.filter_map(|entry| {
|
||||||
let card = entry.deser().map_err_trace_exit_unwrap(1);
|
let card = entry.deser().map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let str_contains_any = |s: &String, v: &Vec<String>| {
|
let str_contains_any = |s: &String, v: &Vec<String>| {
|
||||||
v.iter().any(|i| s.contains(i))
|
v.iter().any(|i| s.contains(i))
|
||||||
|
@ -329,7 +329,7 @@ fn find(rt: &Runtime) {
|
||||||
let s = fmt
|
let s = fmt
|
||||||
.render("format", &data)
|
.render("format", &data)
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let _ = writeln!(rt.stdout(), "{}", s)
|
let _ = writeln!(rt.stdout(), "{}", s)
|
||||||
.to_exit_code()
|
.to_exit_code()
|
||||||
|
@ -348,19 +348,19 @@ fn get_contact_print_format(config_value_path: &'static str, rt: &Runtime, scmd:
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
rt.config()
|
rt.config()
|
||||||
.ok_or_else(|| Error::from(err_msg("No configuration file")))
|
.ok_or_else(|| Error::from(err_msg("No configuration file")))
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.read_string(config_value_path)
|
.read_string(config_value_path)
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.ok_or_else(|| Error::from(err_msg("Configuration 'contact.list_format' does not exist")))
|
.ok_or_else(|| Error::from(err_msg("Configuration 'contact.list_format' does not exist")))
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut hb = Handlebars::new();
|
let mut hb = Handlebars::new();
|
||||||
let _ = hb
|
let _ = hb
|
||||||
.register_template_string("format", fmt)
|
.register_template_string("format", fmt)
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
hb.register_escape_fn(::handlebars::no_escape);
|
hb.register_escape_fn(::handlebars::no_escape);
|
||||||
::libimaginteraction::format::register_all_color_helpers(&mut hb);
|
::libimaginteraction::format::register_all_color_helpers(&mut hb);
|
||||||
|
|
|
@ -29,6 +29,7 @@ use libimagdiary::diary::Diary;
|
||||||
use libimagentryedit::edit::Edit;
|
use libimagentryedit::edit::Edit;
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
use libimagutil::warn_exit::warn_exit;
|
use libimagutil::warn_exit::warn_exit;
|
||||||
use libimagutil::debug_result::DebugResult;
|
use libimagutil::debug_result::DebugResult;
|
||||||
use libimagutil::debug_option::DebugOption;
|
use libimagutil::debug_option::DebugOption;
|
||||||
|
@ -55,7 +56,7 @@ pub fn create(rt: &Runtime) {
|
||||||
entry.edit_content(rt).context(err_msg("Diary edit error")).map_err(Error::from)
|
entry.edit_content(rt).context(err_msg("Diary edit error")).map_err(Error::from)
|
||||||
};
|
};
|
||||||
|
|
||||||
let _ = res.map_err_trace_exit_unwrap(1);
|
let _ = res.map_err_trace_exit_unwrap();
|
||||||
info!("Ok!");
|
info!("Ok!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,10 +66,10 @@ fn create_entry<'a>(diary: &'a Store, diaryname: &str, rt: &Runtime) -> FileLock
|
||||||
let create = rt.cli().subcommand_matches("create").unwrap();
|
let create = rt.cli().subcommand_matches("create").unwrap();
|
||||||
|
|
||||||
create.value_of("timed")
|
create.value_of("timed")
|
||||||
.map(|t| parse_timed_string(t, diaryname).map_err_trace_exit_unwrap(1))
|
.map(|t| parse_timed_string(t, diaryname).map_err_trace_exit_unwrap())
|
||||||
.map(Some)
|
.map(Some)
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
match get_diary_timed_config(rt, diaryname).map_err_trace_exit_unwrap(1) {
|
match get_diary_timed_config(rt, diaryname).map_err_trace_exit_unwrap() {
|
||||||
Some(t) => Some(t),
|
Some(t) => Some(t),
|
||||||
None => {
|
None => {
|
||||||
warn!("Missing config: 'diary.diaries.{}.timed'", diaryname);
|
warn!("Missing config: 'diary.diaries.{}.timed'", diaryname);
|
||||||
|
@ -88,7 +89,7 @@ fn create_entry<'a>(diary: &'a Store, diaryname: &str, rt: &Runtime) -> FileLock
|
||||||
diary.new_entry_today(diaryname)
|
diary.new_entry_today(diaryname)
|
||||||
})
|
})
|
||||||
.map_dbg(|e| format!("Created: {}", e.get_location()))
|
.map_dbg(|e| format!("Created: {}", e.get_location()))
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ use libimagtimeui::parse::Parse;
|
||||||
use libimagutil::warn_exit::warn_exit;
|
use libimagutil::warn_exit::warn_exit;
|
||||||
use libimagstore::storeid::IntoStoreId;
|
use libimagstore::storeid::IntoStoreId;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
|
|
||||||
use util::get_diary_name;
|
use util::get_diary_name;
|
||||||
|
|
||||||
|
@ -48,7 +49,7 @@ pub fn delete(rt: &Runtime) {
|
||||||
.ok_or_else(|| warn_exit("Not deleting entries: missing date/time specification", 1))
|
.ok_or_else(|| warn_exit("Not deleting entries: missing date/time specification", 1))
|
||||||
.and_then(|dt: NDT| DiaryId::from_datetime(diaryname.clone(), dt).into_storeid())
|
.and_then(|dt: NDT| DiaryId::from_datetime(diaryname.clone(), dt).into_storeid())
|
||||||
.and_then(|id| rt.store().retrieve(id))
|
.and_then(|id| rt.store().retrieve(id))
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.get_location()
|
.get_location()
|
||||||
.clone();
|
.clone();
|
||||||
|
|
||||||
|
@ -60,7 +61,7 @@ pub fn delete(rt: &Runtime) {
|
||||||
let mut output = rt.stdout();
|
let mut output = rt.stdout();
|
||||||
|
|
||||||
if !ask_bool(&format!("Deleting {:?}", to_del_location), Some(true), &mut input, &mut output)
|
if !ask_bool(&format!("Deleting {:?}", to_del_location), Some(true), &mut input, &mut output)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
{
|
{
|
||||||
info!("Aborting delete action");
|
info!("Aborting delete action");
|
||||||
return;
|
return;
|
||||||
|
@ -71,7 +72,7 @@ pub fn delete(rt: &Runtime) {
|
||||||
let _ = rt
|
let _ = rt
|
||||||
.store()
|
.store()
|
||||||
.delete(to_del_location)
|
.delete(to_del_location)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
info!("Ok!");
|
info!("Ok!");
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,11 +41,11 @@ pub fn list(rt: &Runtime) {
|
||||||
|
|
||||||
let mut ids = Diary::entries(rt.store(), &diaryname)
|
let mut ids = Diary::entries(rt.store(), &diaryname)
|
||||||
.map_dbg_str("Ok")
|
.map_dbg_str("Ok")
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.map(|id| DiaryId::from_storeid(&id))
|
.map(|id| DiaryId::from_storeid(&id))
|
||||||
.collect::<Result<Vec<_>>>()
|
.collect::<Result<Vec<_>>>()
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
ids.sort_by_key(|id| {
|
ids.sort_by_key(|id| {
|
||||||
[id.year() as u32, id.month(), id.day(), id.hour(), id.minute(), id.second()]
|
[id.year() as u32, id.month(), id.day(), id.hour(), id.minute(), id.second()]
|
||||||
|
@ -53,7 +53,7 @@ pub fn list(rt: &Runtime) {
|
||||||
|
|
||||||
ids.into_iter()
|
ids.into_iter()
|
||||||
.map(IntoStoreId::into_storeid)
|
.map(IntoStoreId::into_storeid)
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.for_each(|id| {
|
.for_each(|id| {
|
||||||
let _ = rt.report_touched(&id).unwrap_or_exit();
|
let _ = rt.report_touched(&id).unwrap_or_exit();
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ fn main() {
|
||||||
other => {
|
other => {
|
||||||
debug!("Unknown command");
|
debug!("Unknown command");
|
||||||
let _ = rt.handle_unknown_subcommand("imag-diary", other, rt.cli())
|
let _ = rt.handle_unknown_subcommand("imag-diary", other, rt.cli())
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.code()
|
.code()
|
||||||
.map(::std::process::exit);
|
.map(::std::process::exit);
|
||||||
},
|
},
|
||||||
|
@ -111,8 +111,8 @@ fn diaries(rt: &Runtime) {
|
||||||
|
|
||||||
rt.store()
|
rt.store()
|
||||||
.diary_names()
|
.diary_names()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.unique()
|
.unique()
|
||||||
.for_each(|n| writeln!(outlock, "{}", n).to_exit_code().unwrap_or_exit())
|
.for_each(|n| writeln!(outlock, "{}", n).to_exit_code().unwrap_or_exit())
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ use libimagdiary::viewer::DiaryViewer as DV;
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
use libimagerror::iter::TraceIterator;
|
use libimagerror::iter::TraceIterator;
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
use libimagutil::warn_exit::warn_exit;
|
use libimagutil::warn_exit::warn_exit;
|
||||||
use libimagstore::iter::get::StoreIdGetIteratorExtension;
|
use libimagstore::iter::get::StoreIdGetIteratorExtension;
|
||||||
use libimagentryview::viewer::Viewer;
|
use libimagentryview::viewer::Viewer;
|
||||||
|
@ -33,9 +34,9 @@ pub fn view(rt: &Runtime) {
|
||||||
let hdr = rt.cli().subcommand_matches("view").unwrap().is_present("show-header");
|
let hdr = rt.cli().subcommand_matches("view").unwrap().is_present("show-header");
|
||||||
|
|
||||||
let entries = Diary::entries(rt.store(), &diaryname)
|
let entries = Diary::entries(rt.store(), &diaryname)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.into_get_iter(rt.store())
|
.into_get_iter(rt.store())
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.map(|e| e.unwrap_or_else(|| {
|
.map(|e| e.unwrap_or_else(|| {
|
||||||
error!("Failed to fetch entry");
|
error!("Failed to fetch entry");
|
||||||
::std::process::exit(1)
|
::std::process::exit(1)
|
||||||
|
@ -49,6 +50,6 @@ pub fn view(rt: &Runtime) {
|
||||||
|
|
||||||
let out = rt.stdout();
|
let out = rt.stdout();
|
||||||
DV::new(hdr).view_entries(entries, &mut out.lock())
|
DV::new(hdr).view_entries(entries, &mut out.lock())
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,7 +99,7 @@ fn main() {
|
||||||
other => {
|
other => {
|
||||||
debug!("Unknown command");
|
debug!("Unknown command");
|
||||||
let _ = rt.handle_unknown_subcommand("imag-habit", other, rt.cli())
|
let _ = rt.handle_unknown_subcommand("imag-habit", other, rt.cli())
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.code()
|
.code()
|
||||||
.map(::std::process::exit);
|
.map(::std::process::exit);
|
||||||
},
|
},
|
||||||
|
@ -117,10 +117,10 @@ fn create(rt: &Runtime) {
|
||||||
let comm = scmd.value_of("create-comment").map(String::from).unwrap(); // safe by clap
|
let comm = scmd.value_of("create-comment").map(String::from).unwrap(); // safe by clap
|
||||||
let date = scmd.value_of("create-date").unwrap(); // safe by clap
|
let date = scmd.value_of("create-date").unwrap(); // safe by clap
|
||||||
|
|
||||||
let parsedate = |d, pname| match kairos_parse(d).map_err_trace_exit_unwrap(1) {
|
let parsedate = |d, pname| match kairos_parse(d).map_err_trace_exit_unwrap() {
|
||||||
Parsed::TimeType(tt) => tt.calculate()
|
Parsed::TimeType(tt) => tt.calculate()
|
||||||
.map_dbg(|y| format!("TimeType yielded: '{:?}'", y))
|
.map_dbg(|y| format!("TimeType yielded: '{:?}'", y))
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.get_moment()
|
.get_moment()
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
error!("Error: '{}' parameter does not yield a point in time", pname);
|
error!("Error: '{}' parameter does not yield a point in time", pname);
|
||||||
|
@ -154,7 +154,7 @@ fn create(rt: &Runtime) {
|
||||||
|
|
||||||
debug!("Builder = {:?}", hb);
|
debug!("Builder = {:?}", hb);
|
||||||
|
|
||||||
let fle = hb.build(rt.store()).map_err_trace_exit_unwrap(1);
|
let fle = hb.build(rt.store()).map_err_trace_exit_unwrap();
|
||||||
let _ = rt.report_touched(fle.get_location()).unwrap_or_exit();
|
let _ = rt.report_touched(fle.get_location()).unwrap_or_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,11 +176,11 @@ fn delete(rt: &Runtime) {
|
||||||
let _ = rt
|
let _ = rt
|
||||||
.store()
|
.store()
|
||||||
.all_habit_templates()
|
.all_habit_templates()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.map(|sid| (sid.clone(), rt.store().get(sid).map_err_trace_exit_unwrap(1))) // get the FileLockEntry
|
.map(|sid| (sid.clone(), rt.store().get(sid).map_err_trace_exit_unwrap())) // get the FileLockEntry
|
||||||
.filter(|&(_, ref habit)| match habit { // filter for name of habit == name we look for
|
.filter(|&(_, ref habit)| match habit { // filter for name of habit == name we look for
|
||||||
&Some(ref h) => h.habit_name().map_err_trace_exit_unwrap(1) == name,
|
&Some(ref h) => h.habit_name().map_err_trace_exit_unwrap() == name,
|
||||||
&None => false,
|
&None => false,
|
||||||
})
|
})
|
||||||
.filter_map(|(a, o)| o.map(|x| (a, x))) // map: (a, Option<b>) -> Option<(a, b)> -> (a, b)
|
.filter_map(|(a, o)| o.map(|x| (a, x))) // map: (a, Option<b>) -> Option<(a, b)> -> (a, b)
|
||||||
|
@ -188,18 +188,18 @@ fn delete(rt: &Runtime) {
|
||||||
if delete_instances {
|
if delete_instances {
|
||||||
|
|
||||||
// if this does not succeed, we did something terribly wrong
|
// if this does not succeed, we did something terribly wrong
|
||||||
let t_name = fle.habit_name().map_err_trace_exit_unwrap(1);
|
let t_name = fle.habit_name().map_err_trace_exit_unwrap();
|
||||||
assert_eq!(t_name, name);
|
assert_eq!(t_name, name);
|
||||||
|
|
||||||
let get_instance = |iid| rt.store().get(iid).map_err_trace_exit_unwrap(1);
|
let get_instance = |iid| rt.store().get(iid).map_err_trace_exit_unwrap();
|
||||||
let has_template_name = |i: &FileLockEntry| t_name == i.get_template_name().map_err_trace_exit_unwrap(1);
|
let has_template_name = |i: &FileLockEntry| t_name == i.get_template_name().map_err_trace_exit_unwrap();
|
||||||
let instance_location = |i: FileLockEntry| i.get_location().clone();
|
let instance_location = |i: FileLockEntry| i.get_location().clone();
|
||||||
let delete_instance_by_id = |id| {
|
let delete_instance_by_id = |id| {
|
||||||
let do_delete = |id| rt.store().delete(id).map_err_trace_exit_unwrap(1);
|
let do_delete = |id| rt.store().delete(id).map_err_trace_exit_unwrap();
|
||||||
if !yes {
|
if !yes {
|
||||||
let q = format!("Really delete {}", id);
|
let q = format!("Really delete {}", id);
|
||||||
if ask_bool(&q, Some(false), &mut input, &mut output)
|
if ask_bool(&q, Some(false), &mut input, &mut output)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
{
|
{
|
||||||
let _ = do_delete(id);
|
let _ = do_delete(id);
|
||||||
}
|
}
|
||||||
|
@ -210,8 +210,8 @@ fn delete(rt: &Runtime) {
|
||||||
|
|
||||||
let _ = fle
|
let _ = fle
|
||||||
.linked_instances()
|
.linked_instances()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.filter_map(get_instance)
|
.filter_map(get_instance)
|
||||||
.filter(has_template_name)
|
.filter(has_template_name)
|
||||||
.map(instance_location)
|
.map(instance_location)
|
||||||
|
@ -221,11 +221,11 @@ fn delete(rt: &Runtime) {
|
||||||
|
|
||||||
drop(fle);
|
drop(fle);
|
||||||
|
|
||||||
let do_delete_template = |sid| rt.store().delete(sid).map_err_trace_exit_unwrap(1);
|
let do_delete_template = |sid| rt.store().delete(sid).map_err_trace_exit_unwrap();
|
||||||
if !yes {
|
if !yes {
|
||||||
let q = format!("Really delete template {}", sid);
|
let q = format!("Really delete template {}", sid);
|
||||||
if ask_bool(&q, Some(false), &mut input, &mut output)
|
if ask_bool(&q, Some(false), &mut input, &mut output)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
{
|
{
|
||||||
let _ = do_delete_template(sid);
|
let _ = do_delete_template(sid);
|
||||||
}
|
}
|
||||||
|
@ -267,8 +267,8 @@ fn today(rt: &Runtime, future: bool) {
|
||||||
let mut relevant : Vec<_> = rt
|
let mut relevant : Vec<_> = rt
|
||||||
.store()
|
.store()
|
||||||
.all_habit_templates()
|
.all_habit_templates()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.filter_map(|id| match rt.store().get(id.clone()) {
|
.filter_map(|id| match rt.store().get(id.clone()) {
|
||||||
Ok(Some(h)) => Some(h),
|
Ok(Some(h)) => Some(h),
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
|
@ -281,7 +281,7 @@ fn today(rt: &Runtime, future: bool) {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.filter(|h| {
|
.filter(|h| {
|
||||||
let due = h.next_instance_date().map_err_trace_exit_unwrap(1);
|
let due = h.next_instance_date().map_err_trace_exit_unwrap();
|
||||||
// today or in future
|
// today or in future
|
||||||
debug!("Checking {due:?} == {today:?} or (future = {fut} && {due:?} > {today:?}",
|
debug!("Checking {due:?} == {today:?} or (future = {fut} && {due:?} > {today:?}",
|
||||||
due = due, today = today, fut = future);
|
due = due, today = today, fut = future);
|
||||||
|
@ -290,14 +290,14 @@ fn today(rt: &Runtime, future: bool) {
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// unwrap is safe because we filtered above
|
// unwrap is safe because we filtered above
|
||||||
relevant.sort_by_key(|h| h.next_instance_date().map_err_trace_exit_unwrap(1).unwrap());
|
relevant.sort_by_key(|h| h.next_instance_date().map_err_trace_exit_unwrap().unwrap());
|
||||||
relevant
|
relevant
|
||||||
};
|
};
|
||||||
|
|
||||||
let any_today_relevant = show_done || relevant
|
let any_today_relevant = show_done || relevant
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|h| {
|
.filter(|h| {
|
||||||
let due = h.next_instance_date().map_err_trace_exit_unwrap(1);
|
let due = h.next_instance_date().map_err_trace_exit_unwrap();
|
||||||
debug!("Checking: {:?} == {:?}", due, today);
|
debug!("Checking: {:?} == {:?}", due, today);
|
||||||
due.map(|d| d == today).unwrap_or(false) // relevant today
|
due.map(|d| d == today).unwrap_or(false) // relevant today
|
||||||
})
|
})
|
||||||
|
@ -314,7 +314,7 @@ fn today(rt: &Runtime, future: bool) {
|
||||||
x.parse::<usize>()
|
x.parse::<usize>()
|
||||||
.context(format_err!("Cannot parse String '{}' to integer", x))
|
.context(format_err!("Cannot parse String '{}' to integer", x))
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
})
|
})
|
||||||
}).unwrap_or(5);
|
}).unwrap_or(5);
|
||||||
|
|
||||||
|
@ -322,13 +322,13 @@ fn today(rt: &Runtime, future: bool) {
|
||||||
info!("Upcoming:");
|
info!("Upcoming:");
|
||||||
// list `n` which are relevant in the future.
|
// list `n` which are relevant in the future.
|
||||||
relevant.iter().take(n).for_each(|element| {
|
relevant.iter().take(n).for_each(|element| {
|
||||||
let date = element.next_instance_date().map_err_trace_exit_unwrap(1);
|
let date = element.next_instance_date().map_err_trace_exit_unwrap();
|
||||||
let name = element.habit_name().map_err_trace_exit_unwrap(1);
|
let name = element.habit_name().map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
if let Some(date) = date {
|
if let Some(date) = date {
|
||||||
let is_done = element
|
let is_done = element
|
||||||
.instance_exists_for_date(&date)
|
.instance_exists_for_date(&date)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
if show_done || !is_done {
|
if show_done || !is_done {
|
||||||
info!(" * {date}: {name}", date = date, name = name);
|
info!(" * {date}: {name}", date = date, name = name);
|
||||||
|
@ -338,13 +338,13 @@ fn today(rt: &Runtime, future: bool) {
|
||||||
} else {
|
} else {
|
||||||
fn lister_fn(h: &FileLockEntry) -> Vec<String> {
|
fn lister_fn(h: &FileLockEntry) -> Vec<String> {
|
||||||
debug!("Listing: {:?}", h);
|
debug!("Listing: {:?}", h);
|
||||||
let name = h.habit_name().map_err_trace_exit_unwrap(1);
|
let name = h.habit_name().map_err_trace_exit_unwrap();
|
||||||
let basedate = h.habit_basedate().map_err_trace_exit_unwrap(1);
|
let basedate = h.habit_basedate().map_err_trace_exit_unwrap();
|
||||||
let recur = h.habit_recur_spec().map_err_trace_exit_unwrap(1);
|
let recur = h.habit_recur_spec().map_err_trace_exit_unwrap();
|
||||||
let due = h.next_instance_date().map_err_trace_exit_unwrap(1)
|
let due = h.next_instance_date().map_err_trace_exit_unwrap()
|
||||||
.map(date_to_string_helper)
|
.map(date_to_string_helper)
|
||||||
.unwrap_or_else(|| String::from("<finished>"));
|
.unwrap_or_else(|| String::from("<finished>"));
|
||||||
let comm = h.habit_comment().map_err_trace_exit_unwrap(1);
|
let comm = h.habit_comment().map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let v = vec![name, basedate, recur, due, comm];
|
let v = vec![name, basedate, recur, due, comm];
|
||||||
debug!(" -> {:?}", v);
|
debug!(" -> {:?}", v);
|
||||||
|
@ -365,10 +365,10 @@ fn today(rt: &Runtime, future: bool) {
|
||||||
.filter(|habit| show_done || {
|
.filter(|habit| show_done || {
|
||||||
habit
|
habit
|
||||||
.next_instance_date()
|
.next_instance_date()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.map(|date| {
|
.map(|date| {
|
||||||
habit.instance_exists_for_date(&date)
|
habit.instance_exists_for_date(&date)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
})
|
})
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
})
|
})
|
||||||
|
@ -380,7 +380,7 @@ fn today(rt: &Runtime, future: bool) {
|
||||||
{
|
{
|
||||||
let _ = rt
|
let _ = rt
|
||||||
.report_touched(e.get_location())
|
.report_touched(e.get_location())
|
||||||
.map_err_trace_exit_unwrap(1);
|
.unwrap_or_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
v.append(&mut list);
|
v.append(&mut list);
|
||||||
|
@ -397,11 +397,11 @@ fn today(rt: &Runtime, future: bool) {
|
||||||
fn list(rt: &Runtime) {
|
fn list(rt: &Runtime) {
|
||||||
fn lister_fn(h: &FileLockEntry) -> Vec<String> {
|
fn lister_fn(h: &FileLockEntry) -> Vec<String> {
|
||||||
debug!("Listing: {:?}", h);
|
debug!("Listing: {:?}", h);
|
||||||
let name = h.habit_name().map_err_trace_exit_unwrap(1);
|
let name = h.habit_name().map_err_trace_exit_unwrap();
|
||||||
let basedate = h.habit_basedate().map_err_trace_exit_unwrap(1);
|
let basedate = h.habit_basedate().map_err_trace_exit_unwrap();
|
||||||
let recur = h.habit_recur_spec().map_err_trace_exit_unwrap(1);
|
let recur = h.habit_recur_spec().map_err_trace_exit_unwrap();
|
||||||
let comm = h.habit_comment().map_err_trace_exit_unwrap(1);
|
let comm = h.habit_comment().map_err_trace_exit_unwrap();
|
||||||
let due = h.next_instance_date().map_err_trace_exit_unwrap(1)
|
let due = h.next_instance_date().map_err_trace_exit_unwrap()
|
||||||
.map(date_to_string_helper)
|
.map(date_to_string_helper)
|
||||||
.unwrap_or_else(|| String::from("<finished>"));
|
.unwrap_or_else(|| String::from("<finished>"));
|
||||||
|
|
||||||
|
@ -422,8 +422,8 @@ fn list(rt: &Runtime) {
|
||||||
let _ = rt
|
let _ = rt
|
||||||
.store()
|
.store()
|
||||||
.all_habit_templates()
|
.all_habit_templates()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.filter_map(|id| match rt.store().get(id.clone()) {
|
.filter_map(|id| match rt.store().get(id.clone()) {
|
||||||
Ok(Some(h)) => Some(h),
|
Ok(Some(h)) => Some(h),
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
|
@ -465,8 +465,8 @@ fn show(rt: &Runtime) {
|
||||||
use libimagutil::date::date_to_string;
|
use libimagutil::date::date_to_string;
|
||||||
use libimaghabit::instance::HabitInstance;
|
use libimaghabit::instance::HabitInstance;
|
||||||
|
|
||||||
let date = date_to_string(&i.get_date().map_err_trace_exit_unwrap(1));
|
let date = date_to_string(&i.get_date().map_err_trace_exit_unwrap());
|
||||||
let comm = i.get_comment().map_err_trace_exit_unwrap(1);
|
let comm = i.get_comment().map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
vec![date, comm]
|
vec![date, comm]
|
||||||
}
|
}
|
||||||
|
@ -482,16 +482,16 @@ fn show(rt: &Runtime) {
|
||||||
let _ = rt
|
let _ = rt
|
||||||
.store()
|
.store()
|
||||||
.all_habit_templates()
|
.all_habit_templates()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.filter_map(|id| get_from_store(rt.store(), id))
|
.filter_map(|id| get_from_store(rt.store(), id))
|
||||||
.filter(|h| h.habit_name().map(|n| name == n).map_err_trace_exit_unwrap(1))
|
.filter(|h| h.habit_name().map(|n| name == n).map_err_trace_exit_unwrap())
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, habit)| {
|
.map(|(i, habit)| {
|
||||||
let name = habit.habit_name().map_err_trace_exit_unwrap(1);
|
let name = habit.habit_name().map_err_trace_exit_unwrap();
|
||||||
let basedate = habit.habit_basedate().map_err_trace_exit_unwrap(1);
|
let basedate = habit.habit_basedate().map_err_trace_exit_unwrap();
|
||||||
let recur = habit.habit_recur_spec().map_err_trace_exit_unwrap(1);
|
let recur = habit.habit_recur_spec().map_err_trace_exit_unwrap();
|
||||||
let comm = habit.habit_comment().map_err_trace_exit_unwrap(1);
|
let comm = habit.habit_comment().map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let _ = writeln!(rt.stdout(),
|
let _ = writeln!(rt.stdout(),
|
||||||
"{i} - {name}\nBase : {b},\nRecurrence: {r}\nComment : {c}\n",
|
"{i} - {name}\nBase : {b},\nRecurrence: {r}\nComment : {c}\n",
|
||||||
|
@ -506,11 +506,11 @@ fn show(rt: &Runtime) {
|
||||||
let mut empty = true;
|
let mut empty = true;
|
||||||
let _ = habit
|
let _ = habit
|
||||||
.linked_instances()
|
.linked_instances()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.filter_map(|instance_id| {
|
.filter_map(|instance_id| {
|
||||||
debug!("Getting: {:?}", instance_id);
|
debug!("Getting: {:?}", instance_id);
|
||||||
rt.store().get(instance_id).map_err_trace_exit_unwrap(1)
|
rt.store().get(instance_id).map_err_trace_exit_unwrap()
|
||||||
})
|
})
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.for_each(|(i, e)| {
|
.for_each(|(i, e)| {
|
||||||
|
@ -543,31 +543,31 @@ fn done(rt: &Runtime) {
|
||||||
let mut relevant : Vec<_> = rt
|
let mut relevant : Vec<_> = rt
|
||||||
.store()
|
.store()
|
||||||
.all_habit_templates()
|
.all_habit_templates()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.filter_map(|id| get_from_store(rt.store(), id))
|
.filter_map(|id| get_from_store(rt.store(), id))
|
||||||
.filter(|h| {
|
.filter(|h| {
|
||||||
let due = h.next_instance_date().map_err_trace_exit_unwrap(1);
|
let due = h.next_instance_date().map_err_trace_exit_unwrap();
|
||||||
due.map(|d| (d == today || d < today) || scmd.is_present("allow-future"))
|
due.map(|d| (d == today || d < today) || scmd.is_present("allow-future"))
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
})
|
})
|
||||||
.filter(|h| {
|
.filter(|h| {
|
||||||
names.contains(&h.habit_name().map_err_trace_exit_unwrap(1))
|
names.contains(&h.habit_name().map_err_trace_exit_unwrap())
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// unwrap is safe because we filtered above
|
// unwrap is safe because we filtered above
|
||||||
relevant.sort_by_key(|h| h.next_instance_date().map_err_trace_exit_unwrap(1).unwrap());
|
relevant.sort_by_key(|h| h.next_instance_date().map_err_trace_exit_unwrap().unwrap());
|
||||||
relevant
|
relevant
|
||||||
};
|
};
|
||||||
|
|
||||||
for mut r in relevant {
|
for mut r in relevant {
|
||||||
let next_instance_name = r.habit_name().map_err_trace_exit_unwrap(1);
|
let next_instance_name = r.habit_name().map_err_trace_exit_unwrap();
|
||||||
let next_instance_date = r.next_instance_date().map_err_trace_exit_unwrap(1);
|
let next_instance_date = r.next_instance_date().map_err_trace_exit_unwrap();
|
||||||
if let Some(next) = next_instance_date {
|
if let Some(next) = next_instance_date {
|
||||||
debug!("Creating new instance on {:?}", next);
|
debug!("Creating new instance on {:?}", next);
|
||||||
r.create_instance_with_date(rt.store(), &next)
|
r.create_instance_with_date(rt.store(), &next)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
info!("Done on {date}: {name}",
|
info!("Done on {date}: {name}",
|
||||||
date = libimagutil::date::date_to_string(&next),
|
date = libimagutil::date::date_to_string(&next),
|
||||||
|
|
|
@ -84,7 +84,7 @@ fn main() {
|
||||||
other => {
|
other => {
|
||||||
debug!("Unknown command");
|
debug!("Unknown command");
|
||||||
let _ = rt.handle_unknown_subcommand("imag-log", other, rt.cli())
|
let _ = rt.handle_unknown_subcommand("imag-log", other, rt.cli())
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.code()
|
.code()
|
||||||
.map(::std::process::exit);
|
.map(::std::process::exit);
|
||||||
},
|
},
|
||||||
|
@ -102,10 +102,10 @@ fn main() {
|
||||||
.store()
|
.store()
|
||||||
.new_entry_now(&diary_name)
|
.new_entry_now(&diary_name)
|
||||||
.map(|mut fle| {
|
.map(|mut fle| {
|
||||||
let _ = fle.make_log_entry().map_err_trace_exit_unwrap(1);
|
let _ = fle.make_log_entry().map_err_trace_exit_unwrap();
|
||||||
*fle.get_content_mut() = text;
|
*fle.get_content_mut() = text;
|
||||||
})
|
})
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,18 +118,18 @@ fn show(rt: &Runtime) {
|
||||||
let scmd = rt.cli().subcommand_matches("show").unwrap(); // safed by main()
|
let scmd = rt.cli().subcommand_matches("show").unwrap(); // safed by main()
|
||||||
let iters : Vec<DiaryEntryIterator> = match scmd.values_of("show-name") {
|
let iters : Vec<DiaryEntryIterator> = match scmd.values_of("show-name") {
|
||||||
Some(values) => values
|
Some(values) => values
|
||||||
.map(|diary_name| Diary::entries(rt.store(), diary_name).map_err_trace_exit_unwrap(1))
|
.map(|diary_name| Diary::entries(rt.store(), diary_name).map_err_trace_exit_unwrap())
|
||||||
.collect(),
|
.collect(),
|
||||||
|
|
||||||
None => if scmd.is_present("show-all") {
|
None => if scmd.is_present("show-all") {
|
||||||
debug!("Showing for all diaries");
|
debug!("Showing for all diaries");
|
||||||
rt.store()
|
rt.store()
|
||||||
.diary_names()
|
.diary_names()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.map(|diary_name| {
|
.map(|diary_name| {
|
||||||
let diary_name = diary_name.map_err_trace_exit_unwrap(1);
|
let diary_name = diary_name.map_err_trace_exit_unwrap();
|
||||||
debug!("Getting entries for Diary: {}", diary_name);
|
debug!("Getting entries for Diary: {}", diary_name);
|
||||||
let entries = Diary::entries(rt.store(), &diary_name).map_err_trace_exit_unwrap(1);
|
let entries = Diary::entries(rt.store(), &diary_name).map_err_trace_exit_unwrap();
|
||||||
let diary_name = Cow::from(diary_name);
|
let diary_name = Cow::from(diary_name);
|
||||||
(entries, diary_name)
|
(entries, diary_name)
|
||||||
})
|
})
|
||||||
|
@ -138,13 +138,13 @@ fn show(rt: &Runtime) {
|
||||||
.collect()
|
.collect()
|
||||||
} else {
|
} else {
|
||||||
// showing default logs
|
// showing default logs
|
||||||
vec![Diary::entries(rt.store(), &get_diary_name(rt)).map_err_trace_exit_unwrap(1)]
|
vec![Diary::entries(rt.store(), &get_diary_name(rt)).map_err_trace_exit_unwrap()]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Itertools::flatten(iters.into_iter())
|
Itertools::flatten(iters.into_iter())
|
||||||
.into_get_iter(rt.store())
|
.into_get_iter(rt.store())
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.filter_map(|opt| {
|
.filter_map(|opt| {
|
||||||
if opt.is_none() {
|
if opt.is_none() {
|
||||||
warn!("Failed to retrieve an entry from an existing store id");
|
warn!("Failed to retrieve an entry from an existing store id");
|
||||||
|
@ -152,8 +152,8 @@ fn show(rt: &Runtime) {
|
||||||
|
|
||||||
opt
|
opt
|
||||||
})
|
})
|
||||||
.filter(|e| e.is_log().map_err_trace_exit_unwrap(1))
|
.filter(|e| e.is_log().map_err_trace_exit_unwrap())
|
||||||
.map(|entry| (entry.diary_id().map_err_trace_exit_unwrap(1), entry))
|
.map(|entry| (entry.diary_id().map_err_trace_exit_unwrap(), entry))
|
||||||
.sorted_by_key(|tpl| tpl.0.clone())
|
.sorted_by_key(|tpl| tpl.0.clone())
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|tpl| { debug!("Found entry: {:?}", tpl.1); tpl })
|
.map(|tpl| { debug!("Found entry: {:?}", tpl.1); tpl })
|
||||||
|
@ -185,24 +185,24 @@ fn get_diary_name(rt: &Runtime) -> String {
|
||||||
let cfg = rt
|
let cfg = rt
|
||||||
.config()
|
.config()
|
||||||
.ok_or_else(|| Error::from(err_msg("Configuration not present, cannot continue")))
|
.ok_or_else(|| Error::from(err_msg("Configuration not present, cannot continue")))
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let current_log = cfg
|
let current_log = cfg
|
||||||
.read_string("log.default")
|
.read_string("log.default")
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.ok_or_else(|| Error::from(err_msg("Configuration missing: 'log.default'")))
|
.ok_or_else(|| Error::from(err_msg("Configuration missing: 'log.default'")))
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
if cfg
|
if cfg
|
||||||
.read("log.logs")
|
.read("log.logs")
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.ok_or_else(|| Error::from(err_msg("Configuration missing: 'log.logs'")))
|
.ok_or_else(|| Error::from(err_msg("Configuration missing: 'log.logs'")))
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.as_array()
|
.as_array()
|
||||||
.ok_or_else(|| Error::from(err_msg("Configuration 'log.logs' is not an Array")))
|
.ok_or_else(|| Error::from(err_msg("Configuration 'log.logs' is not an Array")))
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|e| if is_match!(e, &Value::String(_)) {
|
.map(|e| if is_match!(e, &Value::String(_)) {
|
||||||
error!("Configuration 'log.logs' is not an Array<String>!");
|
error!("Configuration 'log.logs' is not an Array<String>!");
|
||||||
|
|
|
@ -79,7 +79,7 @@ fn main() {
|
||||||
other => {
|
other => {
|
||||||
debug!("Unknown command");
|
debug!("Unknown command");
|
||||||
let _ = rt.handle_unknown_subcommand("imag-mail", other, rt.cli())
|
let _ = rt.handle_unknown_subcommand("imag-mail", other, rt.cli())
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.code()
|
.code()
|
||||||
.map(::std::process::exit);
|
.map(::std::process::exit);
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ fn import_mail(rt: &Runtime) {
|
||||||
|
|
||||||
let mail = Mail::import_from_path(rt.store(), path)
|
let mail = Mail::import_from_path(rt.store(), path)
|
||||||
.map_info_str("Ok")
|
.map_info_str("Ok")
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let _ = rt.report_touched(mail.fle().get_location()).unwrap_or_exit();
|
let _ = rt.report_touched(mail.fle().get_location()).unwrap_or_exit();
|
||||||
}
|
}
|
||||||
|
@ -152,15 +152,15 @@ fn list(rt: &Runtime) {
|
||||||
|
|
||||||
let _ = rt.store()
|
let _ = rt.store()
|
||||||
.entries()
|
.entries()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.filter(|id| id.is_in_collection(&["mail"]))
|
.filter(|id| id.is_in_collection(&["mail"]))
|
||||||
.filter_map(|id| {
|
.filter_map(|id| {
|
||||||
rt.store()
|
rt.store()
|
||||||
.get(id)
|
.get(id)
|
||||||
.context(err_msg("Ref handling error"))
|
.context(err_msg("Ref handling error"))
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.map(|fle| Mail::from_fle(fle).map_err_trace().ok())
|
.map(|fle| Mail::from_fle(fle).map_err_trace().ok())
|
||||||
})
|
})
|
||||||
.filter_map(|e| e)
|
.filter_map(|e| e)
|
||||||
|
|
|
@ -86,7 +86,7 @@ fn main() {
|
||||||
other => {
|
other => {
|
||||||
debug!("Unknown command");
|
debug!("Unknown command");
|
||||||
let _ = rt.handle_unknown_subcommand("imag-notes", other, rt.cli())
|
let _ = rt.handle_unknown_subcommand("imag-notes", other, rt.cli())
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.code()
|
.code()
|
||||||
.map(::std::process::exit);
|
.map(::std::process::exit);
|
||||||
},
|
},
|
||||||
|
@ -103,13 +103,13 @@ fn create(rt: &Runtime) {
|
||||||
let mut note = rt
|
let mut note = rt
|
||||||
.store()
|
.store()
|
||||||
.new_note(name.clone(), String::new())
|
.new_note(name.clone(), String::new())
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
if rt.cli().subcommand_matches("create").unwrap().is_present("edit") {
|
if rt.cli().subcommand_matches("create").unwrap().is_present("edit") {
|
||||||
let _ = note
|
let _ = note
|
||||||
.edit_content(rt)
|
.edit_content(rt)
|
||||||
.map_warn_err_str("Editing failed")
|
.map_warn_err_str("Editing failed")
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = rt.report_touched(note.get_location()).unwrap_or_exit();
|
let _ = rt.report_touched(note.get_location()).unwrap_or_exit();
|
||||||
|
@ -119,7 +119,7 @@ fn delete(rt: &Runtime) {
|
||||||
let _ = rt.store()
|
let _ = rt.store()
|
||||||
.delete_note(name_from_cli(rt, "delete"))
|
.delete_note(name_from_cli(rt, "delete"))
|
||||||
.map_info_str("Ok")
|
.map_info_str("Ok")
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn edit(rt: &Runtime) {
|
fn edit(rt: &Runtime) {
|
||||||
|
@ -127,12 +127,12 @@ fn edit(rt: &Runtime) {
|
||||||
let _ = rt
|
let _ = rt
|
||||||
.store()
|
.store()
|
||||||
.get_note(name.clone())
|
.get_note(name.clone())
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.map(|mut note| {
|
.map(|mut note| {
|
||||||
let _ = note
|
let _ = note
|
||||||
.edit_content(rt)
|
.edit_content(rt)
|
||||||
.map_warn_err_str("Editing failed")
|
.map_warn_err_str("Editing failed")
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let _ = rt.report_touched(note.get_location()).unwrap_or_exit();
|
let _ = rt.report_touched(note.get_location()).unwrap_or_exit();
|
||||||
})
|
})
|
||||||
|
@ -147,9 +147,9 @@ fn list(rt: &Runtime) {
|
||||||
let _ = rt
|
let _ = rt
|
||||||
.store()
|
.store()
|
||||||
.all_notes()
|
.all_notes()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.into_get_iter(rt.store())
|
.into_get_iter(rt.store())
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.map(|opt| opt.unwrap_or_else(|| {
|
.map(|opt| opt.unwrap_or_else(|| {
|
||||||
error!("Fatal: Nonexistent entry where entry should exist");
|
error!("Fatal: Nonexistent entry where entry should exist");
|
||||||
exit(1)
|
exit(1)
|
||||||
|
@ -161,7 +161,7 @@ fn list(rt: &Runtime) {
|
||||||
})
|
})
|
||||||
.iter()
|
.iter()
|
||||||
.for_each(|note| {
|
.for_each(|note| {
|
||||||
let name = note.get_name().map_err_trace_exit_unwrap(1);
|
let name = note.get_name().map_err_trace_exit_unwrap();
|
||||||
let _ = writeln!(rt.stdout(), "{}", name)
|
let _ = writeln!(rt.stdout(), "{}", name)
|
||||||
.to_exit_code()
|
.to_exit_code()
|
||||||
.unwrap_or_exit();
|
.unwrap_or_exit();
|
||||||
|
|
|
@ -26,6 +26,7 @@ use chrono::NaiveDateTime;
|
||||||
use libimagerror::trace::trace_error;
|
use libimagerror::trace::trace_error;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
use libimagerror::iter::TraceIterator;
|
use libimagerror::iter::TraceIterator;
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
||||||
use libimagtimetrack::timetracking::TimeTracking;
|
use libimagtimetrack::timetracking::TimeTracking;
|
||||||
use libimagtimetrack::iter::filter::*;
|
use libimagtimetrack::iter::filter::*;
|
||||||
|
@ -35,7 +36,7 @@ use libimagrt::runtime::Runtime;
|
||||||
pub fn cont(rt: &Runtime) -> i32 {
|
pub fn cont(rt: &Runtime) -> i32 {
|
||||||
let groups = rt.store()
|
let groups = rt.store()
|
||||||
.get_timetrackings()
|
.get_timetrackings()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.trace_unwrap()
|
.trace_unwrap()
|
||||||
.filter(|e| has_end_time.filter(&e))
|
.filter(|e| has_end_time.filter(&e))
|
||||||
.group_by(|elem| match elem.get_end_datetime() { // Now group them by the end time
|
.group_by(|elem| match elem.get_end_datetime() { // Now group them by the end time
|
||||||
|
@ -98,6 +99,6 @@ pub fn cont(rt: &Runtime) -> i32 {
|
||||||
info!("No trackings to continue");
|
info!("No trackings to continue");
|
||||||
Ok(1)
|
Ok(1)
|
||||||
},
|
},
|
||||||
}.map_err_trace_exit_unwrap(1)
|
}.map_err_trace_exit_unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ use libimagerror::trace::trace_error;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
use libimagerror::iter::TraceIterator;
|
use libimagerror::iter::TraceIterator;
|
||||||
use libimagerror::io::ToExitCode;
|
use libimagerror::io::ToExitCode;
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
||||||
use libimagtimetrack::timetracking::TimeTracking;
|
use libimagtimetrack::timetracking::TimeTracking;
|
||||||
|
@ -88,7 +89,7 @@ pub fn day(rt: &Runtime) -> i32 {
|
||||||
|
|
||||||
rt.store()
|
rt.store()
|
||||||
.get_timetrackings()
|
.get_timetrackings()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.trace_unwrap()
|
.trace_unwrap()
|
||||||
.filter(|e| filter.filter(e))
|
.filter(|e| filter.filter(e))
|
||||||
.map(|e| -> Result<_, Error> {
|
.map(|e| -> Result<_, Error> {
|
||||||
|
@ -107,7 +108,7 @@ pub fn day(rt: &Runtime) -> i32 {
|
||||||
|
|
||||||
Ok((tag, start, end))
|
Ok((tag, start, end))
|
||||||
})
|
})
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.map(|(tag, start, end)| {
|
.map(|(tag, start, end)| {
|
||||||
match (start, end) {
|
match (start, end) {
|
||||||
(None, _) => writeln!(rt.stdout(), "{} has no start time.", tag),
|
(None, _) => writeln!(rt.stdout(), "{} has no start time.", tag),
|
||||||
|
|
|
@ -33,6 +33,7 @@ use failure::Error;
|
||||||
use libimagerror::trace::trace_error;
|
use libimagerror::trace::trace_error;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
use libimagerror::iter::TraceIterator;
|
use libimagerror::iter::TraceIterator;
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
||||||
use libimagtimetrack::timetracking::TimeTracking;
|
use libimagtimetrack::timetracking::TimeTracking;
|
||||||
|
@ -122,7 +123,7 @@ pub fn list_impl(rt: &Runtime,
|
||||||
|
|
||||||
rt.store()
|
rt.store()
|
||||||
.get_timetrackings()
|
.get_timetrackings()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.trace_unwrap()
|
.trace_unwrap()
|
||||||
.filter(|e| filter.filter(e))
|
.filter(|e| filter.filter(e))
|
||||||
.fold(Ok(table), |acc: Result<_>, e| {
|
.fold(Ok(table), |acc: Result<_>, e| {
|
||||||
|
@ -167,7 +168,7 @@ pub fn list_impl(rt: &Runtime,
|
||||||
Ok(tab)
|
Ok(tab)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.print(&mut rt.stdout())
|
.print(&mut rt.stdout())
|
||||||
.context(err_msg("Failed to print table"))
|
.context(err_msg("Failed to print table"))
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
|
|
|
@ -99,7 +99,7 @@ fn main() {
|
||||||
other => {
|
other => {
|
||||||
debug!("Unknown command");
|
debug!("Unknown command");
|
||||||
rt.handle_unknown_subcommand("imag-timetrack", other, rt.cli())
|
rt.handle_unknown_subcommand("imag-timetrack", other, rt.cli())
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.code()
|
.code()
|
||||||
.unwrap_or(0)
|
.unwrap_or(0)
|
||||||
},
|
},
|
||||||
|
|
|
@ -28,6 +28,7 @@ use libimagerror::trace::trace_error;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
use libimagerror::io::ToExitCode;
|
use libimagerror::io::ToExitCode;
|
||||||
use libimagerror::iter::TraceIterator;
|
use libimagerror::iter::TraceIterator;
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
||||||
use libimagtimetrack::timetracking::TimeTracking;
|
use libimagtimetrack::timetracking::TimeTracking;
|
||||||
|
@ -103,7 +104,7 @@ pub fn month(rt: &Runtime) -> i32 {
|
||||||
|
|
||||||
rt.store()
|
rt.store()
|
||||||
.get_timetrackings()
|
.get_timetrackings()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.trace_unwrap()
|
.trace_unwrap()
|
||||||
.filter(|e| filter.filter(e))
|
.filter(|e| filter.filter(e))
|
||||||
.map(|e| -> Result<_, Error> {
|
.map(|e| -> Result<_, Error> {
|
||||||
|
@ -118,11 +119,11 @@ pub fn month(rt: &Runtime) -> i32 {
|
||||||
let end = e.get_end_datetime()?;
|
let end = e.get_end_datetime()?;
|
||||||
debug!(" -> end = {:?}", end);
|
debug!(" -> end = {:?}", end);
|
||||||
|
|
||||||
let _ = rt.report_touched(e.get_location()).unwrap_or_exit(1);
|
let _ = rt.report_touched(e.get_location()).unwrap_or_exit();
|
||||||
|
|
||||||
Ok((tag, start, end))
|
Ok((tag, start, end))
|
||||||
})
|
})
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.map(|(tag, start, end)| {
|
.map(|(tag, start, end)| {
|
||||||
match (start, end) {
|
match (start, end) {
|
||||||
(None, _) => writeln!(rt.stdout(), "{} has no start time.", tag),
|
(None, _) => writeln!(rt.stdout(), "{} has no start time.", tag),
|
||||||
|
|
|
@ -24,7 +24,7 @@ use failure::Error;
|
||||||
|
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagerror::trace::trace_error;
|
use libimagerror::trace::trace_error;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::exit::ExitUnwrap;
|
||||||
use libimagtimetrack::tag::TimeTrackingTag;
|
use libimagtimetrack::tag::TimeTrackingTag;
|
||||||
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ use failure::Error;
|
||||||
use libimagerror::trace::trace_error;
|
use libimagerror::trace::trace_error;
|
||||||
use libimagerror::iter::TraceIterator;
|
use libimagerror::iter::TraceIterator;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
|
|
||||||
use libimagtimetrack::timetracking::TimeTracking;
|
use libimagtimetrack::timetracking::TimeTracking;
|
||||||
|
@ -57,12 +58,12 @@ pub fn stop(rt: &Runtime) -> i32 {
|
||||||
// Get all timetrackings which do not have an end datetime.
|
// Get all timetrackings which do not have an end datetime.
|
||||||
rt.store()
|
rt.store()
|
||||||
.get_timetrackings()
|
.get_timetrackings()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.trace_unwrap()
|
.trace_unwrap()
|
||||||
.filter_map(|tracking| {
|
.filter_map(|tracking| {
|
||||||
let is_none = tracking
|
let is_none = tracking
|
||||||
.get_end_datetime()
|
.get_end_datetime()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.is_none();
|
.is_none();
|
||||||
|
|
||||||
if is_none {
|
if is_none {
|
||||||
|
@ -72,7 +73,7 @@ pub fn stop(rt: &Runtime) -> i32 {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.map(|t| t.get_timetrack_tag())
|
.map(|t| t.get_timetrack_tag())
|
||||||
.map(|r| r.map_err_trace_exit_unwrap(1))
|
.map(|r| r.map_err_trace_exit_unwrap())
|
||||||
.collect()
|
.collect()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -82,7 +83,7 @@ pub fn stop(rt: &Runtime) -> i32 {
|
||||||
.store()
|
.store()
|
||||||
.get_timetrackings()
|
.get_timetrackings()
|
||||||
.map_warn_err_str("Getting timetrackings failed")
|
.map_warn_err_str("Getting timetrackings failed")
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.trace_unwrap()
|
.trace_unwrap()
|
||||||
|
|
||||||
// Filter all timetrackings for the ones that are not yet ended.
|
// Filter all timetrackings for the ones that are not yet ended.
|
||||||
|
|
|
@ -26,9 +26,9 @@ use failure::Error;
|
||||||
|
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagerror::trace::trace_error;
|
use libimagerror::trace::trace_error;
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
use libimagtimetrack::tag::TimeTrackingTag;
|
use libimagtimetrack::tag::TimeTrackingTag;
|
||||||
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
||||||
use libimagerror::trace::MapErrTrace;
|
|
||||||
|
|
||||||
const DATE_TIME_PARSE_FMT : &'static str = "%Y-%m-%dT%H:%M:%S";
|
const DATE_TIME_PARSE_FMT : &'static str = "%Y-%m-%dT%H:%M:%S";
|
||||||
const DATE_PARSE_FMT : &'static str = "%Y-%m-%d";
|
const DATE_PARSE_FMT : &'static str = "%Y-%m-%d";
|
||||||
|
|
|
@ -28,6 +28,7 @@ use libimagerror::trace::trace_error;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
use libimagerror::iter::TraceIterator;
|
use libimagerror::iter::TraceIterator;
|
||||||
use libimagerror::io::ToExitCode;
|
use libimagerror::io::ToExitCode;
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
||||||
use libimagtimetrack::timetracking::TimeTracking;
|
use libimagtimetrack::timetracking::TimeTracking;
|
||||||
|
@ -101,7 +102,7 @@ pub fn week(rt: &Runtime) -> i32 {
|
||||||
|
|
||||||
rt.store()
|
rt.store()
|
||||||
.get_timetrackings()
|
.get_timetrackings()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.trace_unwrap()
|
.trace_unwrap()
|
||||||
.filter(|e| filter.filter(e))
|
.filter(|e| filter.filter(e))
|
||||||
.map(|e| -> Result<_, Error> {
|
.map(|e| -> Result<_, Error> {
|
||||||
|
@ -120,7 +121,7 @@ pub fn week(rt: &Runtime) -> i32 {
|
||||||
|
|
||||||
Ok((tag, start, end))
|
Ok((tag, start, end))
|
||||||
})
|
})
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.map(|(tag, start, end)| {
|
.map(|(tag, start, end)| {
|
||||||
match (start, end) {
|
match (start, end) {
|
||||||
(None, _) => writeln!(rt.stdout(), "{} has no start time.", tag),
|
(None, _) => writeln!(rt.stdout(), "{} has no start time.", tag),
|
||||||
|
|
|
@ -28,6 +28,7 @@ use libimagerror::trace::trace_error;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
use libimagerror::iter::TraceIterator;
|
use libimagerror::iter::TraceIterator;
|
||||||
use libimagerror::io::ToExitCode;
|
use libimagerror::io::ToExitCode;
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
||||||
use libimagtimetrack::timetracking::TimeTracking;
|
use libimagtimetrack::timetracking::TimeTracking;
|
||||||
|
@ -101,7 +102,7 @@ pub fn year(rt: &Runtime) -> i32 {
|
||||||
let mut out = rt.stdout();
|
let mut out = rt.stdout();
|
||||||
rt.store()
|
rt.store()
|
||||||
.get_timetrackings()
|
.get_timetrackings()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.trace_unwrap()
|
.trace_unwrap()
|
||||||
.filter(|e| filter.filter(e))
|
.filter(|e| filter.filter(e))
|
||||||
.map(|e| -> Result<_, Error> {
|
.map(|e| -> Result<_, Error> {
|
||||||
|
@ -120,7 +121,7 @@ pub fn year(rt: &Runtime) -> i32 {
|
||||||
|
|
||||||
Ok((tag, start, end))
|
Ok((tag, start, end))
|
||||||
})
|
})
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.map(|(tag, start, end)| {
|
.map(|(tag, start, end)| {
|
||||||
match (start, end) {
|
match (start, end) {
|
||||||
(None, _) => writeln!(out, "{} has no start time.", tag),
|
(None, _) => writeln!(out, "{} has no start time.", tag),
|
||||||
|
|
|
@ -74,7 +74,7 @@ fn main() {
|
||||||
Some(other) => {
|
Some(other) => {
|
||||||
debug!("Unknown command");
|
debug!("Unknown command");
|
||||||
let _ = rt.handle_unknown_subcommand("imag-todo", other, rt.cli())
|
let _ = rt.handle_unknown_subcommand("imag-todo", other, rt.cli())
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.code()
|
.code()
|
||||||
.map(::std::process::exit);
|
.map(::std::process::exit);
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ fn tw_hook(rt: &Runtime) {
|
||||||
let (_, line, uuid ) = rt
|
let (_, line, uuid ) = rt
|
||||||
.store()
|
.store()
|
||||||
.import_task_from_reader(stdin)
|
.import_task_from_reader(stdin)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let _ = writeln!(rt.stdout(), "{}\nTask {} stored in imag", line, uuid)
|
let _ = writeln!(rt.stdout(), "{}\nTask {} stored in imag", line, uuid)
|
||||||
.to_exit_code()
|
.to_exit_code()
|
||||||
|
@ -129,7 +129,7 @@ fn list(rt: &Runtime) {
|
||||||
let res = rt.store().all_tasks() // get all tasks
|
let res = rt.store().all_tasks() // get all tasks
|
||||||
.map(|iter| { // and if this succeeded
|
.map(|iter| { // and if this succeeded
|
||||||
// filter out the ones were we can read the uuid
|
// filter out the ones were we can read the uuid
|
||||||
let uuids : Vec<_> = iter.trace_unwrap_exit(1).filter_map(|storeid| {
|
let uuids : Vec<_> = iter.trace_unwrap_exit().filter_map(|storeid| {
|
||||||
match rt.store().retrieve(storeid) {
|
match rt.store().retrieve(storeid) {
|
||||||
Ok(fle) => {
|
Ok(fle) => {
|
||||||
match fle.get_header().read_string("todo.uuid") {
|
match fle.get_header().read_string("todo.uuid") {
|
||||||
|
|
|
@ -65,7 +65,7 @@ fn main() {
|
||||||
Some(other) => {
|
Some(other) => {
|
||||||
debug!("Unknown command");
|
debug!("Unknown command");
|
||||||
let _ = rt.handle_unknown_subcommand("imag-wiki", other, rt.cli())
|
let _ = rt.handle_unknown_subcommand("imag-wiki", other, rt.cli())
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.code()
|
.code()
|
||||||
.map(std::process::exit);
|
.map(std::process::exit);
|
||||||
}
|
}
|
||||||
|
@ -86,14 +86,14 @@ fn ids(rt: &Runtime, wiki_name: &str) {
|
||||||
|
|
||||||
rt.store()
|
rt.store()
|
||||||
.get_wiki(wiki_name)
|
.get_wiki(wiki_name)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
error!("No wiki '{}' found", wiki_name);
|
error!("No wiki '{}' found", wiki_name);
|
||||||
::std::process::exit(1)
|
::std::process::exit(1)
|
||||||
})
|
})
|
||||||
.all_ids()
|
.all_ids()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit()
|
||||||
.for_each(|id| {
|
.for_each(|id| {
|
||||||
let _ = writeln!(outlock, "{}{}", prefix, id)
|
let _ = writeln!(outlock, "{}{}", prefix, id)
|
||||||
.to_exit_code()
|
.to_exit_code()
|
||||||
|
@ -114,13 +114,13 @@ fn idof(rt: &Runtime, wiki_name: &str) {
|
||||||
|
|
||||||
let _ = rt.store()
|
let _ = rt.store()
|
||||||
.get_wiki(wiki_name)
|
.get_wiki(wiki_name)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
error!("No wiki '{}' found", wiki_name);
|
error!("No wiki '{}' found", wiki_name);
|
||||||
::std::process::exit(1)
|
::std::process::exit(1)
|
||||||
})
|
})
|
||||||
.get_entry(&entryname)
|
.get_entry(&entryname)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.map(|entry| {
|
.map(|entry| {
|
||||||
let id = entry.get_location().clone();
|
let id = entry.get_location().clone();
|
||||||
let prefix = if scmd.is_present("idof-full") {
|
let prefix = if scmd.is_present("idof-full") {
|
||||||
|
@ -147,30 +147,30 @@ fn create(rt: &Runtime, wiki_name: &str) {
|
||||||
let wiki = rt
|
let wiki = rt
|
||||||
.store()
|
.store()
|
||||||
.get_wiki(&wiki_name)
|
.get_wiki(&wiki_name)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
error!("No wiki '{}' found", wiki_name);
|
error!("No wiki '{}' found", wiki_name);
|
||||||
::std::process::exit(1)
|
::std::process::exit(1)
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut entry = wiki.create_entry(name).map_err_trace_exit_unwrap(1);
|
let mut entry = wiki.create_entry(name).map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
if !scmd.is_present("create-noedit") {
|
if !scmd.is_present("create-noedit") {
|
||||||
if scmd.is_present("create-editheader") {
|
if scmd.is_present("create-editheader") {
|
||||||
let _ = entry.edit_header_and_content(rt).map_err_trace_exit_unwrap(1);
|
let _ = entry.edit_header_and_content(rt).map_err_trace_exit_unwrap();
|
||||||
} else {
|
} else {
|
||||||
let _ = entry.edit_content(rt).map_err_trace_exit_unwrap(1);
|
let _ = entry.edit_content(rt).map_err_trace_exit_unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = entry.autolink(rt.store())
|
let _ = entry.autolink(rt.store())
|
||||||
.map_warn_err_str("Linking has failed. Trying to safe the entry now. Please investigate by hand if this succeeds.")
|
.map_warn_err_str("Linking has failed. Trying to safe the entry now. Please investigate by hand if this succeeds.")
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
let _ = rt.store().update(&mut entry).map_err_trace_exit_unwrap(1);
|
let _ = rt.store().update(&mut entry).map_err_trace_exit_unwrap();
|
||||||
e
|
e
|
||||||
})
|
})
|
||||||
.map_warn_err_str("Safed entry")
|
.map_warn_err_str("Safed entry")
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let id = entry.get_location();
|
let id = entry.get_location();
|
||||||
|
|
||||||
|
@ -187,7 +187,7 @@ fn create(rt: &Runtime, wiki_name: &str) {
|
||||||
fn create_wiki(rt: &Runtime) {
|
fn create_wiki(rt: &Runtime) {
|
||||||
let scmd = rt.cli().subcommand_matches("create-wiki").unwrap(); // safed by clap
|
let scmd = rt.cli().subcommand_matches("create-wiki").unwrap(); // safed by clap
|
||||||
let wiki_name = String::from(scmd.value_of("create-wiki-name").unwrap()); // safe by clap
|
let wiki_name = String::from(scmd.value_of("create-wiki-name").unwrap()); // safe by clap
|
||||||
let (_, index) = rt.store().create_wiki(&wiki_name).map_err_trace_exit_unwrap(1);
|
let (_, index) = rt.store().create_wiki(&wiki_name).map_err_trace_exit_unwrap();
|
||||||
|
|
||||||
let _ = rt.report_touched(index.get_location()).unwrap_or_exit();
|
let _ = rt.report_touched(index.get_location()).unwrap_or_exit();
|
||||||
}
|
}
|
||||||
|
@ -221,7 +221,7 @@ fn show(rt: &Runtime, wiki_name: &str) {
|
||||||
let wiki = rt
|
let wiki = rt
|
||||||
.store()
|
.store()
|
||||||
.get_wiki(&wiki_name)
|
.get_wiki(&wiki_name)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
error!("No wiki '{}' found", wiki_name);
|
error!("No wiki '{}' found", wiki_name);
|
||||||
::std::process::exit(1)
|
::std::process::exit(1)
|
||||||
|
@ -233,7 +233,7 @@ fn show(rt: &Runtime, wiki_name: &str) {
|
||||||
for name in names {
|
for name in names {
|
||||||
let entry = wiki
|
let entry = wiki
|
||||||
.get_entry(&name)
|
.get_entry(&name)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
error!("No wiki entry '{}' found in wiki '{}'", name, wiki_name);
|
error!("No wiki entry '{}' found in wiki '{}'", name, wiki_name);
|
||||||
::std::process::exit(1)
|
::std::process::exit(1)
|
||||||
|
@ -261,7 +261,7 @@ fn delete(rt: &Runtime, wiki_name: &str) {
|
||||||
let wiki = rt
|
let wiki = rt
|
||||||
.store()
|
.store()
|
||||||
.get_wiki(&wiki_name)
|
.get_wiki(&wiki_name)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
error!("No wiki '{}' found", wiki_name);
|
error!("No wiki '{}' found", wiki_name);
|
||||||
::std::process::exit(1)
|
::std::process::exit(1)
|
||||||
|
@ -269,17 +269,17 @@ fn delete(rt: &Runtime, wiki_name: &str) {
|
||||||
|
|
||||||
if unlink {
|
if unlink {
|
||||||
wiki.get_entry(&name)
|
wiki.get_entry(&name)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap()
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
error!("No wiki entry '{}' in '{}' found", name, wiki_name);
|
error!("No wiki entry '{}' in '{}' found", name, wiki_name);
|
||||||
::std::process::exit(1)
|
::std::process::exit(1)
|
||||||
})
|
})
|
||||||
.unlink(rt.store())
|
.unlink(rt.store())
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = wiki
|
let _ = wiki
|
||||||
.delete_entry(&name)
|
.delete_entry(&name)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ impl<I, F, T> Iterator for UnwrapWith<I, F>
|
||||||
|
|
||||||
|
|
||||||
/// Iterator helper for Unwrap with exiting on error
|
/// Iterator helper for Unwrap with exiting on error
|
||||||
pub struct UnwrapExit<I, T>(I, i32)
|
pub struct UnwrapExit<I, T>(I)
|
||||||
where I: Iterator<Item = Result<T, Error>>;
|
where I: Iterator<Item = Result<T, Error>>;
|
||||||
|
|
||||||
impl<I, T> Iterator for UnwrapExit<I, T>
|
impl<I, T> Iterator for UnwrapExit<I, T>
|
||||||
|
@ -69,7 +69,7 @@ impl<I, T> Iterator for UnwrapExit<I, T>
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
use trace::MapErrTrace;
|
use trace::MapErrTrace;
|
||||||
self.0.next().map(|e| e.map_err_trace_exit_unwrap(self.1))
|
self.0.next().map(|e| e.map_err_trace_exit_unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ impl<I, T> DoubleEndedIterator for UnwrapExit<I, T>
|
||||||
{
|
{
|
||||||
fn next_back(&mut self) -> Option<Self::Item> {
|
fn next_back(&mut self) -> Option<Self::Item> {
|
||||||
use trace::MapErrTrace;
|
use trace::MapErrTrace;
|
||||||
self.0.next_back().map(|e| e.map_err_trace_exit_unwrap(self.1))
|
self.0.next_back().map(|e| e.map_err_trace_exit_unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,8 +111,8 @@ pub trait TraceIterator<T> : Iterator<Item = Result<T, Error>> + Sized {
|
||||||
/// nothing will be passed to `::trace::trace_error_exit`, no matter how many `Err` items might
|
/// nothing will be passed to `::trace::trace_error_exit`, no matter how many `Err` items might
|
||||||
/// be present.
|
/// be present.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn trace_unwrap_exit(self, exitcode: i32) -> UnwrapExit<Self, T> {
|
fn trace_unwrap_exit(self) -> UnwrapExit<Self, T> {
|
||||||
UnwrapExit(self, exitcode)
|
UnwrapExit(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ pub trait MapErrTrace {
|
||||||
type Output;
|
type Output;
|
||||||
|
|
||||||
fn map_err_trace(self) -> Self;
|
fn map_err_trace(self) -> Self;
|
||||||
fn map_err_trace_exit_unwrap(self, code: i32) -> Self::Output;
|
fn map_err_trace_exit_unwrap(self) -> Self::Output;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<U> MapErrTrace for Result<U, Error> {
|
impl<U> MapErrTrace for Result<U, Error> {
|
||||||
|
@ -87,8 +87,8 @@ impl<U> MapErrTrace for Result<U, Error> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Trace the error and exit or unwrap the Ok(_).
|
/// Trace the error and exit or unwrap the Ok(_).
|
||||||
fn map_err_trace_exit_unwrap(self, code: i32) -> Self::Output {
|
fn map_err_trace_exit_unwrap(self) -> Self::Output {
|
||||||
self.map_err(|e| { trace_error(&e); exit(code) }).unwrap()
|
self.map_err(|e| { trace_error(&e); exit(1) }).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue