diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2019-02-05 01:37:32 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2019-02-11 03:52:04 +0100 |
commit | 90eaeb642af712c6dc556ad8342e6d218c892cc1 (patch) | |
tree | 54764c60307db0bd7dd43c7c6fa222f98be545dd | |
parent | 01fa19aadebbe94c6b759608e2f75f2714b74c94 (diff) |
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>
53 files changed, 377 insertions, 362 deletions
diff --git a/bin/core/imag-annotate/src/main.rs b/bin/core/imag-annotate/src/main.rs index afb5ce6e..c764758d 100644 --- a/bin/core/imag-annotate/src/main.rs +++ b/bin/core/imag-annotate/src/main.rs @@ -87,7 +87,7 @@ fn main() { other => { debug!("Unknown command"); let _ = rt.handle_unknown_subcommand("imag-annotation", other, rt.cli()) - .map_err_trace_exit_unwrap(1) + .map_err_trace_exit_unwrap() .code() .map(::std::process::exit); }, @@ -97,27 +97,27 @@ fn main() { fn add(rt: &Runtime) { 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() { let mut annotation = rt.store() .get(first.clone()) - .map_err_trace_exit_unwrap(1) + .map_err_trace_exit_unwrap() .ok_or_else(|| EM::EntryNotFound(first.local_display_string())) .map_err(Error::from) - .map_err_trace_exit_unwrap(1) + .map_err_trace_exit_unwrap() .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 { 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())) - .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") { @@ -125,7 +125,7 @@ fn add(rt: &Runtime) { .get_header() .read_string("annotation.name") .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) .to_exit_code() @@ -144,19 +144,19 @@ fn remove(rt: &Runtime) { let scmd = rt.cli().subcommand_matches("remove").unwrap(); // safed by main() let annotation_name = scmd.value_of("annotation_name").unwrap(); // safed by clap 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| { let mut entry = rt.store() .get(id.clone()) - .map_err_trace_exit_unwrap(1) + .map_err_trace_exit_unwrap() .ok_or_else(|| EM::EntryNotFound(id.local_display_string())) .map_err(Error::from) - .map_err_trace_exit_unwrap(1); + .map_err_trace_exit_unwrap(); let annotation = entry .denotate(rt.store(), annotation_name) - .map_err_trace_exit_unwrap(1); + .map_err_trace_exit_unwrap(); if delete { debug!("Deleting annotation object"); @@ -167,7 +167,7 @@ fn remove(rt: &Runtime) { let _ = rt .store() .delete(loc) - .map_err_trace_exit_unwrap(1); + .map_err_trace_exit_unwrap(); } else { warn!("Not having annotation object, cannot delete!"); } @@ -181,7 +181,7 @@ fn remove(rt: &Runtime) { fn list(rt: &Runtime) { let scmd = rt.cli().subcommand_matches("list").unwrap(); // safed by clap 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 { let _ = ids @@ -190,16 +190,16 @@ fn list(rt: &Runtime) { let _ = rt .store() .get(id.clone()) - .map_err_trace_exit_unwrap(1) + .map_err_trace_exit_unwrap() .ok_or_else(|| EM::EntryNotFound(id.local_display_string())) .map_err(Error::from) - .map_err_trace_exit_unwrap(1) + .map_err_trace_exit_unwrap() .annotations() - .map_err_trace_exit_unwrap(1) + .map_err_trace_exit_unwrap() .into_get_iter(rt.store()) - .trace_unwrap_exit(1) + .trace_unwrap_exit() .map(|opt| opt.ok_or_else(|| format_err!("Cannot find entry"))) - .trace_unwrap_exit(1) + .trace_unwrap_exit() .enumerate() .for_each(|(i, entry)| list_annotation(&rt, i, entry, with_text)); }); @@ -207,11 +207,11 @@ fn list(rt: &Runtime) { // show them all rt.store() .all_annotations() - .map_err_trace_exit_unwrap(1) + .map_err_trace_exit_unwrap() .into_get_iter(rt.store()) - .trace_unwrap_exit(1) + .trace_unwrap_exit() .map(|opt| opt.ok_or_else(|| format_err!("Cannot find entry"))) - .trace_unwrap_exit(1) + .trace_unwrap_exit() .enumerate() .for_each(|(i, entry)| list_annotation(&rt, i, entry, with_text)); } diff --git a/bin/core/imag-annotate/src/ui.rs b/bin/core/imag-annotate/src/ui.rs index 024d6a3d..72074c08 100644 --- a/bin/core/imag-annotate/src/ui.rs +++ b/bin/core/imag-annotate/src/ui.rs @@ -110,7 +110,7 @@ impl IdPathProvider for PathProvider { .map(PathBuf::from) .map(|pb| pb.into_storeid()) .collect::<Result<Vec<_>, _>>() - .map_err_trace_exit_unwrap(1) + .map_err_trace_exit_unwrap() }, ("remove", Some(subm)) => { @@ -124,7 +124,7 @@ impl IdPathProvider for PathProvider { .map(PathBuf::from) .map(|pb| pb.into_storeid()) .collect::<Result<Vec<_>, _>>() - .map_err_trace_exit_unwrap(1) + .map_err_trace_exit_unwrap() }, ("list", Some(subm)) => { @@ -138,7 +138,7 @@ impl IdPathProvider for PathProvider { .map(PathBuf::from) .map(|pb| pb.into_storeid()) .collect::<Result<Vec<_>, _>>() - .map_err_trace_exit_unwrap(1) + .map_err_trace_exit_unwrap() }, (other, _) => { diff --git a/bin/core/imag-category/src/main.rs b/bin/core/imag-category/src/main.rs index 2a6e8a16..96882e41 100644 --- a/bin/core/imag-category/src/main.rs +++ b/bin/core/imag-category/src/main.rs @@ -81,7 +81,7 @@ fn main() { other => { debug!("Unknown command"); let _ = rt.handle_unknown_subcommand("imag-category", other, rt.cli()) - .map_err_trace_exit_unwrap(1) + .map_err_trace_exit_unwrap() .code() .map(::std::process::exit); }, @@ -92,11 +92,11 @@ fn main() { fn set(rt: &Runtime) { 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 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))) .into_get_iter(rt.store()) - .trace_unwrap_exit(1) + .trace_unwrap_exit() .map(|o| o.unwrap_or_else(|| { error!("Did not find one entry"); ::std::process::exit(1) @@ -104,23 +104,23 @@ fn set(rt: &Runtime) { .for_each(|mut entry| { let _ = entry .set_category_checked(rt.store(), &name) - .map_err_trace_exit_unwrap(1); + .map_err_trace_exit_unwrap(); }) } 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 mut outlock = out.lock(); StoreIdIterator::new(Box::new(sids.into_iter().map(Ok))) .into_get_iter(rt.store()) - .trace_unwrap_exit(1) + .trace_unwrap_exit() .map(|o| o.unwrap_or_else(|| { error!("Did not find one entry"); ::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| { 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 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 mut outlock = out.lock(); category .get_entries(rt.store()) - .map_err_trace_exit_unwrap(1) + .map_err_trace_exit_unwrap() .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() .unwrap_or_exit(); }) @@ -155,7 +155,7 @@ fn create_category(rt: &Runtime) { let _ = rt .store() .create_category(&name) - .map_err_trace_exit_unwrap(1); + .map_err_trace_exit_unwrap(); } fn delete_category(rt: &Runtime) { @@ -170,14 +170,14 @@ fn delete_category(rt: &Runtime) { ::std::process::exit(1) }); 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 { info!("Deleting category '{}'", name); let _ = rt .store() .delete_category(&name) - .map_err_trace_exit_unwrap(1); + .map_err_trace_exit_unwrap(); } else { info!("Not doing anything"); } @@ -189,9 +189,9 @@ fn list_categories(rt: &Runtime) { rt.store() .all_category_names() - .map_err_trace_exit_unwrap(1) + .map_err_trace_exit_unwrap() .for_each(|name| { - writeln!(outlock, "{}", name.map_err_trace_exit_unwrap(1)) + writeln!(outlock, "{}", name.map_err_trace_exit_unwrap()) .to_exit_code() .unwrap_or_exit(); }) diff --git a/bin/core/imag-category/src/ui.rs b/bin/core/imag-category/src/ui.rs index a9b50bfd..fca41bd0 100644 --- a/bin/core/imag-category/src/ui.rs +++ b/bin/core/imag-category/src/ui.rs @@ -136,7 +136,7 @@ impl IdPathProvider for PathProvider { .map(PathBuf::from) .map(|pb| pb.into_storeid()) .collect::<Result<Vec<_>, _>>() - .map_err_trace_exit_unwrap(1) + .map_err_trace_exit_unwrap() }, ("get", Some(subm)) => { @@ -150,7 +150,7 @@ impl IdPathProvider for PathProvider { .map(PathBuf::from) .map(|pb| pb.into_storeid()) .collect::<Result<Vec<_>, _>>() - .map_err_trace_exit_unwrap(1) + .map_err_trace_exit_unwrap() }, (other, _) => { diff --git a/bin/core/imag-diagnostics/src/main.rs b/bin/core/imag-diagnostics/src/main.rs index 47b48b71..257af6a5 100644 --- a/bin/core/imag-diagnostics/src/main.rs +++ b/bin/core/imag-diagnostics/src/main.rs @@ -143,12 +143,12 @@ fn main() { let diags = rt.store() .entries() - .map_err_trace_exit_unwrap(1) + .map_err_trace_exit_unwrap() .into_get_iter() .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()))) - .map_err_trace_exit_unwrap(1) + .map_err_trace_exit_unwrap() }) .map(|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 // better by simply flushing the cache each 100 entries 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; } diag }) .collect::<Result<Vec<_>>>() - .map_err_trace_exit_unwrap(1); + .map_err_trace_exit_unwrap(); spinner.finish(); let n = diags.len(); @@ -244,7 +244,7 @@ fn main() { num, path .into_pathbuf() - .map_err_trace_exit_unwrap(1) + .map_err_trace_exit_unwrap() .to_str() .unwrap_or("Failed converting path to string") ); @@ -257,7 +257,7 @@ fn main() { num, path .into_pathbuf() - .map_err_trace_exit_unwrap(1) + .map_err_trace_exit_unwrap() .to_str() .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| { cfg.read(s) .map_err(Error::from) - .map_err_trace_exit_unwrap(1) + .map_err_trace_exit_unwrap() .map(|opt| match opt { &Value::String(ref s) => s.to_owned(), _ => { diff --git a/bin/core/imag-edit/src/main.rs b/bin/core/imag-edit/src/main.rs index 9eb53cfe..c0a97dd5 100644 --- a/bin/core/imag-edit/src/main.rs +++ b/bin/core/imag-edit/src/main.rs @@ -63,11 +63,11 @@ fn main() { let edit_header = rt.cli().is_present("edit-header"); 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))) .into_get_iter(rt.store()) - .trace_unwrap_exit(1) + .trace_unwrap_exit() .map(|o| o.unwrap_or_else(|| { error!("Did not find one entry"); ::std::process::exit(1) @@ -76,15 +76,15 @@ fn main() { if edit_header { let _ = entry .edit_header_and_content(&rt) - .map_err_trace_exit_unwrap(1); + .map_err_trace_exit_unwrap(); } else if edit_header_only { let _ = entry .edit_header(&rt) - .map_err_trace_exit_unwrap(1); + .map_err_trace_exit_unwrap(); } else { let _ = entry .edit_content(&rt) - .map_err_trace_exit_unwrap(1); + .map_err_trace_exit_unwrap(); } }); } diff --git a/bin/core/imag-edit/src/ui.rs b/bin/core/imag-edit/src/ui.rs index 2b95a84f..3b788251 100644 --- a/bin/core/imag-edit/src/ui.rs +++ b/bin/core/imag-edit/src/ui.rs @@ -66,6 +66,6 @@ impl IdPathProvider for PathProvider { .map(PathBuf::from) .map(|pb| pb.into_storeid()) .collect::<Result<Vec<_>, _>>() - .map_err_trace_exit_unwrap(1) + .map_err_trace_exit_unwrap() } } diff --git a/bin/core/imag-gps/src/main.rs b/bin/core/imag-gps/src/main.rs index ac673062..6ca785d4 100644 --- a/bin/core/imag-gps/src/main.rs +++ b/bin/core/imag-gps/src/main.rs @@ -79,7 +79,7 @@ fn main() { other => { debug!("Unknown command"); let _ = rt.handle_unknown_subcommand("imag-gps", other, rt.cli()) - .map_err_trace_exit_unwrap(1) + .map_err_trace_exit_unwrap() .code() .map(::std::process::exit); } @@ -96,7 +96,7 @@ fn add(rt: &Runtime) { .map(FromStr::from_str) .map(|elem| { 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>>(); @@ -125,18 +125,18 @@ fn add(rt: &Runtime) { }; rt.ids::<::ui::PathProvider>() - .map_err_trace_exit_unwrap(1) + .map_err_trace_exit_unwrap() .into_iter() .for_each(|id| { rt.store() .get(id.clone()) - .map_err_trace_exit_unwrap(1) + .map_err_trace_exit_unwrap() .unwrap_or_else(|| { // if we have Ok(None) error!("No such entry: {}", id); exit(1) }) .set_coordinates(c.clone()) - .map_err_trace_exit_unwrap(1); + .map_err_trace_exit_unwrap(); let _ = rt.report_touched(&id).unwrap_or_exit(); }); @@ -150,24 +150,24 @@ fn remove(rt: &Runtime) { .is_present("print-removed"); // safed by main() rt.ids::<::ui::PathProvider>() - .map_err_trace_exit_unwrap(1) + .map_err_trace_exit_unwrap() .into_iter() .for_each(|id| { let removed_value = rt .store() .get(id.clone()) - .map_err_trace_exit_unwrap(1) + .map_err_trace_exit_unwrap() .unwrap_or_else(|| { // if we have Ok(None) error!("No such entry: {}", id); exit(1) }) .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) error!("Entry had no coordinates: {}", id); 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 { let _ = writeln!(rt.stdout(), "{}", removed_value).to_exit_code().unwrap_or_exit(); @@ -180,19 +180,19 @@ fn remove(rt: &Runtime) { fn get(rt: &Runtime) { let mut stdout = rt.stdout(); rt.ids::<::ui::PathProvider>() - .map_err_trace_exit_unwrap(1) + .map_err_trace_exit_unwrap() .into_iter() .for_each(|id| { let value = rt .store() .get(id.clone()) - .map_err_trace_exit_unwrap(1) + .map_err_trace_exit_unwrap() .unwrap_or_else(|| { // if we have Ok(None) error!("No such entry: {}", id); exit(1) }) .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) error!("Entry has no coordinates: {}", id); exit(1) diff --git a/bin/core/imag-gps/src/ui.rs b/bin/core/imag-gps/src/ui.rs index 878daf67..572e1c48 100644 --- a/bin/core/imag-gps/src/ui.rs +++ b/bin/core/imag-gps/src/ui.rs @@ -112,7 +112,7 @@ impl IdPathProvider for PathProvider { .map(PathBuf::from) .map(|pb| pb.into_storeid()) .collect::<Result<Vec<_>, _>>() - .map_err_trace_exit_unwrap(1) + .map_err_trace_exit_unwrap() }, ("remove", Some(subm)) => { @@ -126,7 +126,7 @@ impl IdPathProvider for PathProvider { .map(PathBuf::from) .map(|pb| pb.into_storeid()) .collect::<Result<Vec<_>, _>>() - .map_err_trace_exit_unwrap(1) + .map_err_trace_exit_unwrap() }, ("get", Some(subm)) => { @@ -140,7 +140,7 @@ impl IdPathProvider for PathProvider { .map(PathBuf::from) .map(|pb| pb.into_storeid()) .collect::<Result<Vec<_>, _>>() - .map_err_trace_exit_unwrap(1) + .map_err_trace_exit_unwrap() }, (other, _) => { diff --git a/bin/core/imag-grep/src/main.rs b/bin/core/imag-grep/src/main.rs index 9ab3c29d..faf5c139 100644 --- a/bin/core/imag-grep/src/main.rs +++ b/bin/core/imag-grep/src/main.rs @@ -87,9 +87,9 |