summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-02-03 19:53:50 +0100
committerMatthias Beyer <mail@beyermatthias.de>2019-02-11 03:22:56 +0100
commitf1a639ea8ca400db5de0864d76a8c2f374bc2bb4 (patch)
treebc0830fb6c00551b0e4e076e5c302e8438fde4e1
parent19912f5e88bf0c0f1a1c521f6f5109ee6fac8cff (diff)
downloadimag-f1a639ea8ca400db5de0864d76a8c2f374bc2bb4.zip
imag-f1a639ea8ca400db5de0864d76a8c2f374bc2bb4.tar.gz
Change id reporting API to return ExitCode
Because this API only errors when write!() errors occur, we can return the exit code as an error here. This way the user of the API can immediately exit if there was an IO error, but the API automatically takes care of the right return value, returning (exiting) with zero (0) if there was an "Broken pipe" error and with one (1) otherwise, which is the expected behaviour here. All calls to that API were changed accordingly. Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--bin/core/imag-gps/src/main.rs12
-rw-r--r--bin/core/imag-grep/src/main.rs4
-rw-r--r--bin/core/imag-ids/src/main.rs5
-rw-r--r--bin/core/imag-link/src/main.rs30
-rw-r--r--bin/core/imag-mv/src/main.rs4
-rw-r--r--bin/core/imag-ref/src/main.rs2
-rw-r--r--bin/core/imag-store/src/create.rs2
-rw-r--r--bin/core/imag-store/src/get.rs2
-rw-r--r--bin/core/imag-store/src/retrieve.rs2
-rw-r--r--bin/core/imag-store/src/update.rs2
-rw-r--r--bin/core/imag-store/src/verify.rs2
-rw-r--r--bin/core/imag-tag/src/main.rs8
-rw-r--r--bin/core/imag-view/src/main.rs9
-rw-r--r--bin/domain/imag-bookmark/src/main.rs22
-rw-r--r--bin/domain/imag-contact/src/create.rs3
-rw-r--r--bin/domain/imag-contact/src/main.rs19
-rw-r--r--bin/domain/imag-diary/src/create.rs2
-rw-r--r--bin/domain/imag-diary/src/delete.rs4
-rw-r--r--bin/domain/imag-diary/src/list.rs4
-rw-r--r--bin/domain/imag-diary/src/view.rs4
-rw-r--r--bin/domain/imag-habit/src/main.rs14
-rw-r--r--bin/domain/imag-log/src/main.rs2
-rw-r--r--bin/domain/imag-mail/src/main.rs4
-rw-r--r--bin/domain/imag-notes/src/main.rs12
-rw-r--r--bin/domain/imag-timetrack/src/cont.rs3
-rw-r--r--bin/domain/imag-timetrack/src/day.rs3
-rw-r--r--bin/domain/imag-timetrack/src/list.rs3
-rw-r--r--bin/domain/imag-timetrack/src/month.rs3
-rw-r--r--bin/domain/imag-timetrack/src/start.rs3
-rw-r--r--bin/domain/imag-timetrack/src/stop.rs3
-rw-r--r--bin/domain/imag-timetrack/src/track.rs3
-rw-r--r--bin/domain/imag-timetrack/src/week.rs3
-rw-r--r--bin/domain/imag-timetrack/src/year.rs3
-rw-r--r--bin/domain/imag-wiki/src/main.rs12
-rw-r--r--lib/core/libimagrt/src/runtime.rs15
35 files changed, 75 insertions, 153 deletions
diff --git a/bin/core/imag-gps/src/main.rs b/bin/core/imag-gps/src/main.rs
index fe57dc1..ac67306 100644
--- a/bin/core/imag-gps/src/main.rs
+++ b/bin/core/imag-gps/src/main.rs
@@ -138,9 +138,7 @@ fn add(rt: &Runtime) {
.set_coordinates(c.clone())
.map_err_trace_exit_unwrap(1);
- let _ = rt
- .report_touched(&id)
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(&id).unwrap_or_exit();
});
}
@@ -175,9 +173,7 @@ fn remove(rt: &Runtime) {
let _ = writeln!(rt.stdout(), "{}", removed_value).to_exit_code().unwrap_or_exit();
}
- let _ = rt
- .report_touched(&id)
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(&id).unwrap_or_exit();
});
}
@@ -204,9 +200,7 @@ fn get(rt: &Runtime) {
let _ = writeln!(stdout, "{}", value).to_exit_code().unwrap_or_exit();
- let _ = rt
- .report_touched(&id)
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(&id).unwrap_or_exit();
})
}
diff --git a/bin/core/imag-grep/src/main.rs b/bin/core/imag-grep/src/main.rs
index 2afefd3..9ab3c29 100644
--- a/bin/core/imag-grep/src/main.rs
+++ b/bin/core/imag-grep/src/main.rs
@@ -125,8 +125,6 @@ fn show(rt: &Runtime, e: &Entry, re: &Regex, opts: &Options, count: &mut usize)
*count += 1;
}
- let _ = rt
- .report_touched(e.get_location())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(e.get_location()).unwrap_or_exit();
}
diff --git a/bin/core/imag-ids/src/main.rs b/bin/core/imag-ids/src/main.rs
index 1e9a54f..2985b13 100644
--- a/bin/core/imag-ids/src/main.rs
+++ b/bin/core/imag-ids/src/main.rs
@@ -127,11 +127,12 @@ fn main() {
trace!("Got output: {:?}", stdout);
iterator.for_each(|id| {
- rt.report_touched(&id).map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(&id).unwrap_or_exit(); // .map_err_trace_exit_unwrap(1);
+
if !rt.output_is_pipe() {
let id = id.to_str().map_err_trace_exit_unwrap(1);
trace!("Writing to {:?}", stdout);
- let _ = writeln!(stdout, "{}", id)
+ writeln!(stdout, "{}", id)
.to_exit_code()
.unwrap_or_exit();
}
diff --git a/bin/core/imag-link/src/main.rs b/bin/core/imag-link/src/main.rs
index 833e487..79f70a4 100644
--- a/bin/core/imag-link/src/main.rs
+++ b/bin/core/imag-link/src/main.rs
@@ -164,7 +164,7 @@ fn link_from_to<'a, I>(rt: &'a Runtime, from: &'a str, to: I)
.map_err_trace_exit_unwrap(1)
.into_iter();
- let _ = rt.report_all_touched(iter).map_err_trace_exit_unwrap(1);
+ let _ = rt.report_all_touched(iter).unwrap_or_exit();
} else {
debug!("Linking internally: {:?} -> {:?}", from, entry);
@@ -187,18 +187,14 @@ fn link_from_to<'a, I>(rt: &'a Runtime, from: &'a str, to: I)
.add_internal_link(&mut to_entry)
.map_err_trace_exit_unwrap(1);
- let _ = rt
- .report_touched(to_entry.get_location())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(to_entry.get_location()).unwrap_or_exit();
}
info!("Ok: {} -> {}", from, entry);
}
- let _ = rt
- .report_touched(from_entry.get_location())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(from_entry.get_location()).unwrap_or_exit();
}
fn remove_linking(rt: &Runtime) {
@@ -226,9 +222,7 @@ fn remove_linking(rt: &Runtime) {
.remove_internal_link(&mut from)
.map_err_trace_exit_unwrap(1);
- let _ = rt
- .report_touched(to_entry.get_location())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(to_entry.get_location()).unwrap_or_exit();
},
Ok(None) => {
// looks like this is not an entry, but a filesystem URI and therefor an
@@ -250,9 +244,7 @@ fn remove_linking(rt: &Runtime) {
}
});
- let _ = rt
- .report_touched(from.get_location())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(from.get_location()).unwrap_or_exit();
}
fn unlink(rt: &Runtime) {
@@ -267,9 +259,7 @@ fn unlink(rt: &Runtime) {
.unlink(rt.store())
.map_err_trace_exit_unwrap(1);
- let _ = rt
- .report_touched(&id)
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(&id).unwrap_or_exit();
});
}
@@ -323,18 +313,14 @@ fn list_linkings(rt: &Runtime) {
})
}
- let _ = rt
- .report_touched(entry.get_location())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(entry.get_location()).unwrap_or_exit();
},
Ok(None) => warn!("Not found: {}", id),
Err(e) => trace_error(&e),
}
- let _ = rt
- .report_touched(&id)
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(&id).unwrap_or_exit();
});
if !list_plain {
diff --git a/bin/core/imag-mv/src/main.rs b/bin/core/imag-mv/src/main.rs
index d061121..118f609 100644
--- a/bin/core/imag-mv/src/main.rs
+++ b/bin/core/imag-mv/src/main.rs
@@ -52,6 +52,7 @@ use std::path::PathBuf;
use libimagrt::setup::generate_runtime_setup;
use libimagerror::trace::MapErrTrace;
use libimagerror::iter::TraceIterator;
+use libimagerror::exit::ExitUnwrap;
use libimagstore::storeid::StoreId;
use libimagstore::store::Store;
use libimagstore::store::FileLockEntry;
@@ -131,8 +132,7 @@ fn main() {
})
.map_err_trace_exit_unwrap(1);
- let _ = rt.report_touched(&destname)
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(&destname).unwrap_or_exit();
// re-add links to moved entry
relink(rt.store(), destname, &mut linked_entries);
diff --git a/bin/core/imag-ref/src/main.rs b/bin/core/imag-ref/src/main.rs
index 2d7e766..ad72cfe 100644
--- a/bin/core/imag-ref/src/main.rs
+++ b/bin/core/imag-ref/src/main.rs
@@ -102,7 +102,7 @@ fn deref(rt: &Runtime) {
.map(|s| info!("{}", s))
.ok(); // safe here because we exited already in the error case
- let _ = rt.report_touched(&id).map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(&id).unwrap_or_exit();
},
None => {
error!("No entry for id '{}' found", id);
diff --git a/bin/core/imag-store/src/create.rs b/bin/core/imag-store/src/create.rs
index fcfc8ec..527a89f 100644
--- a/bin/core/imag-store/src/create.rs
+++ b/bin/core/imag-store/src/create.rs
@@ -63,7 +63,7 @@ pub fn create(rt: &Runtime) {
}
.map_err_trace_exit_unwrap(1);
- let _ = rt.report_touched(&path).map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(&path).unwrap_or_exit();
}
fn create_from_cli_spec(rt: &Runtime, matches: &ArgMatches, path: &StoreId) -> Result<()> {
diff --git a/bin/core/imag-store/src/get.rs b/bin/core/imag-store/src/get.rs
index 271c722..2f1cf87 100644
--- a/bin/core/imag-store/src/get.rs
+++ b/bin/core/imag-store/src/get.rs
@@ -37,7 +37,7 @@ pub fn get(rt: &Runtime) {
let _ = match rt.store().get(path.clone()).map_err_trace_exit_unwrap(1) {
Some(entry) => {
print_entry(rt, scmd, entry);
- let _ = rt.report_touched(&path).map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(&path).unwrap_or_exit();
},
None => info!("No entry found"),
};
diff --git a/bin/core/imag-store/src/retrieve.rs b/bin/core/imag-store/src/retrieve.rs
index 533e45a..4a20d33 100644
--- a/bin/core/imag-store/src/retrieve.rs
+++ b/bin/core/imag-store/src/retrieve.rs
@@ -48,7 +48,7 @@ pub fn retrieve(rt: &Runtime) {
.map_dbg(|e| format!("{:?}", e))
.map_err_trace_exit_unwrap(1);
- let _ = rt.report_touched(&path).map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(&path).unwrap_or_exit();
});
}
diff --git a/bin/core/imag-store/src/update.rs b/bin/core/imag-store/src/update.rs
index 084788e..1302f3d 100644
--- a/bin/core/imag-store/src/update.rs
+++ b/bin/core/imag-store/src/update.rs
@@ -49,7 +49,7 @@ pub fn update(rt: &Runtime) {
debug!("New header set");
}
- let _ = rt.report_touched(locked_e.get_location()).map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(locked_e.get_location()).unwrap_or_exit();
});
}
diff --git a/bin/core/imag-store/src/verify.rs b/bin/core/imag-store/src/verify.rs
index cd2f183..6f2b96a 100644
--- a/bin/core/imag-store/src/verify.rs
+++ b/bin/core/imag-store/src/verify.rs
@@ -47,7 +47,7 @@ pub fn verify(rt: &Runtime) {
};
info!("{: >6} | {: >14} | {:?}", verify, content_len, p.deref());
- let _ = rt.report_touched(fle.get_location()).map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(fle.get_location()).unwrap_or_exit();
status
});
diff --git a/bin/core/imag-tag/src/main.rs b/bin/core/imag-tag/src/main.rs
index 0aee4af..982d50e 100644
--- a/bin/core/imag-tag/src/main.rs
+++ b/bin/core/imag-tag/src/main.rs
@@ -157,9 +157,7 @@ fn alter(rt: &Runtime, path: StoreId, add: Option<Vec<Tag>>, rem: Option<Vec<Tag
},
}
- let _ = rt
- .report_touched(&path)
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(&path).unwrap_or_exit();
}
fn list(path: StoreId, rt: &Runtime) {
@@ -207,9 +205,7 @@ fn list(path: StoreId, rt: &Runtime) {
.unwrap_or_exit();
}
- let _ = rt
- .report_touched(&path)
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(&path).unwrap_or_exit();
}
/// Get the tags which should be added from the commandline
diff --git a/bin/core/imag-view/src/main.rs b/bin/core/imag-view/src/main.rs
index 0c2335b..08c6c0d 100644
--- a/bin/core/imag-view/src/main.rs
+++ b/bin/core/imag-view/src/main.rs
@@ -98,8 +98,7 @@ fn main() {
let files = entries
.map(|entry| {
let tmpfile = create_tempfile_for(&entry, view_header, hide_content);
- rt.report_touched(entry.get_location())
- .map_err_trace_exit_unwrap(1);
+ rt.report_touched(entry.get_location()).unwrap_or_exit();
tmpfile
})
.collect::<Vec<_>>();
@@ -209,8 +208,7 @@ fn main() {
.view_entry(&entry, &mut outlock)
.map_err_trace_exit_unwrap(1);
- rt.report_touched(entry.get_location())
- .map_err_trace_exit_unwrap(1);
+ rt.report_touched(entry.get_location()).unwrap_or_exit();
});
} else {
let mut viewer = StdoutViewer::new(view_header, !hide_content);
@@ -244,8 +242,7 @@ fn main() {
.view_entry(&entry, &mut outlock)
.map_err_trace_exit_unwrap(1);
- rt.report_touched(entry.get_location())
- .map_err_trace_exit_unwrap(1);
+ rt.report_touched(entry.get_location()).unwrap_or_exit();
});
}
}
diff --git a/bin/domain/imag-bookmark/src/main.rs b/bin/domain/imag-bookmark/src/main.rs
index 7b3237d..e5c4208 100644
--- a/bin/domain/imag-bookmark/src/main.rs
+++ b/bin/domain/imag-bookmark/src/main.rs
@@ -101,18 +101,14 @@ fn add(rt: &Runtime) {
.ok_or_else(|| format_err!("No bookmark collection '{}' found", coll))
.map_err_trace_exit_unwrap(1);
- let _ = rt
- .report_touched(collection.get_location())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(collection.get_location()).unwrap_or_exit();
for url in scmd.values_of("urls").unwrap() { // unwrap saved by clap
let new_ids = collection
.add_link(rt.store(), BookmarkLink::from(url))
.map_err_trace_exit_unwrap(1);
- let _ = rt
- .report_all_touched(new_ids.into_iter())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_all_touched(new_ids.into_iter()).unwrap_or_exit();
}
info!("Ready");
@@ -124,7 +120,7 @@ fn collection(rt: &Runtime) {
if scmd.is_present("add") { // adding a new collection
let name = scmd.value_of("add").unwrap();
if let Ok(id) = BookmarkCollectionStore::new(rt.store(), &name) {
- let _ = rt.report_touched(id.get_location()).map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(id.get_location()).unwrap_or_exit();
info!("Created: {}", name);
} else {
warn!("Creating collection {} failed", name);
@@ -151,9 +147,7 @@ fn list(rt: &Runtime) {
.ok_or_else(|| format_err!("No bookmark collection '{}' found", coll))
.map_err_trace_exit_unwrap(1);
- let _ = rt
- .report_touched(collection.get_location())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(collection.get_location()).unwrap_or_exit();
collection
.links(rt.store())
@@ -177,18 +171,14 @@ fn remove(rt: &Runtime) {
.ok_or_else(|| format_err!("No bookmark collection '{}' found", coll))
.map_err_trace_exit_unwrap(1);
- let _ = rt
- .report_touched(collection.get_location())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(collection.get_location()).unwrap_or_exit();
for url in scmd.values_of("urls").unwrap() { // enforced by clap
let removed_links = collection
.remove_link(rt.store(), BookmarkLink::from(url))
.map_err_trace_exit_unwrap(1);
- let _ = rt
- .report_all_touched(removed_links.into_iter())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_all_touched(removed_links.into_iter()).unwrap_or_exit();
}
info!("Ready");
diff --git a/bin/domain/imag-contact/src/create.rs b/bin/domain/imag-contact/src/create.rs
index a470ced..082ed92 100644
--- a/bin/domain/imag-contact/src/create.rs
+++ b/bin/domain/imag-contact/src/create.rs
@@ -204,8 +204,7 @@ pub fn create(rt: &Runtime) {
.create_from_path(&location)
.map_err_trace_exit_unwrap(1);
- let _ = rt.report_touched(entry.get_location())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(entry.get_location()).unwrap_or_exit();
info!("Created entry in store");
} else {
diff --git a/bin/domain/imag-contact/src/main.rs b/bin/domain/imag-contact/src/main.rs
index 3385bee..a68ee6a 100644
--- a/bin/domain/imag-contact/src/main.rs
+++ b/bin/domain/imag-contact/src/main.rs
@@ -125,8 +125,7 @@ fn list(rt: &Runtime) {
.map(|fle| fle.ok_or_else(|| Error::from(err_msg("StoreId not found".to_owned()))))
.trace_unwrap_exit(1)
.map(|fle| {
- let _ = rt.report_touched(fle.get_location())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(fle.get_location()).unwrap_or_exit();
fle
})
.map(|e| e.deser())
@@ -171,9 +170,7 @@ fn import(rt: &Runtime) {
.retrieve_from_path(&path)
.map_err_trace_exit_unwrap(1);
- let _ = rt
- .report_touched(entry.get_location())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(entry.get_location()).unwrap_or_exit();
} else if path.is_dir() {
for entry in WalkDir::new(path).min_depth(1).into_iter() {
let entry = entry
@@ -187,9 +184,7 @@ fn import(rt: &Runtime) {
.retrieve_from_path(&pb)
.map_err_trace_exit_unwrap(1);
- let _ = rt
- .report_touched(fle.get_location())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(fle.get_location()).unwrap_or_exit();
info!("Imported: {}", entry.path().to_str().unwrap_or("<non UTF-8 path>"));
} else {
warn!("Ignoring non-file: {}", entry.path().to_str().unwrap_or("<non UTF-8 path>"));
@@ -228,9 +223,7 @@ fn show(rt: &Runtime) {
.unwrap() // exited above
.starts_with(&hash)
{
- let _ = rt
- .report_touched(entry.get_location())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(entry.get_location()).unwrap_or_exit();
Some(deser)
} else {
None
@@ -285,9 +278,7 @@ fn find(rt: &Runtime) {
|| card.fullname().iter().any(|a| str_contains_any(a, &grepstring));
if take {
- let _ = rt
- .report_touched(entry.get_location())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(entry.get_location()).unwrap_or_exit();
// optimization so we don't have to parse again in the next step
Some((entry, card))
diff --git a/bin/domain/imag-diary/src/create.rs b/bin/domain/imag-diary/src/create.rs
index 788fd33..7e7c47b 100644
--- a/bin/domain/imag-diary/src/create.rs
+++ b/bin/domain/imag-diary/src/create.rs
@@ -45,7 +45,7 @@ pub fn create(rt: &Runtime) {
let mut entry = create_entry(rt.store(), &diaryname, rt);
- let _ = rt.report_touched(entry.get_location()).map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(entry.get_location()).unwrap_or_exit();
let res = if rt.cli().subcommand_matches("create").unwrap().is_present("no-edit") {
debug!("Not editing new diary entry");
diff --git a/bin/domain/imag-diary/src/delete.rs b/bin/domain/imag-diary/src/delete.rs
index 8ce2296..af719ca 100644
--- a/bin/domain/imag-diary/src/delete.rs
+++ b/bin/domain/imag-diary/src/delete.rs
@@ -66,9 +66,7 @@ pub fn delete(rt: &Runtime) {
return;
}
- let _ = rt
- .report_touched(&to_del_location)
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(&to_del_location).unwrap_or_exit();
let _ = rt
.store()
diff --git a/bin/domain/imag-diary/src/list.rs b/bin/domain/imag-diary/src/list.rs
index 7294b46..ce6d748 100644
--- a/bin/domain/imag-diary/src/list.rs
+++ b/bin/domain/imag-diary/src/list.rs
@@ -55,9 +55,7 @@ pub fn list(rt: &Runtime) {
.map(IntoStoreId::into_storeid)
.trace_unwrap_exit(1)
.for_each(|id| {
- let _ = rt
- .report_touched(&id)
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(&id).unwrap_or_exit();
writeln!(rt.stdout(), "{}", id).to_exit_code().unwrap_or_exit()
});
diff --git a/bin/domain/imag-diary/src/view.rs b/bin/domain/imag-diary/src/view.rs
index 5d28b41..dd1c4d6 100644
--- a/bin/domain/imag-diary/src/view.rs
+++ b/bin/domain/imag-diary/src/view.rs
@@ -42,9 +42,7 @@ pub fn view(rt: &Runtime) {
}));
let entries = entries.map(|e| {
- let _ = rt
- .report_touched(e.get_location())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(e.get_location()).unwrap_or_exit();
e
});
diff --git a/bin/domain/imag-habit/src/main.rs b/bin/domain/imag-habit/src/main.rs
index 5c7f8a7..3a822ee 100644
--- a/bin/domain/imag-habit/src/main.rs
+++ b/bin/domain/imag-habit/src/main.rs
@@ -155,7 +155,7 @@ fn create(rt: &Runtime) {
debug!("Builder = {:?}", hb);
let fle = hb.build(rt.store()).map_err_trace_exit_unwrap(1);
- let _ = rt.report_touched(fle.get_location()).map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(fle.get_location()).unwrap_or_exit();
}
fn delete(rt: &Runtime) {
@@ -441,9 +441,7 @@ fn list(rt: &Runtime) {
let mut list = lister_fn(&e);
{
- let _ = rt
- .report_touched(e.get_location())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(e.get_location()).unwrap_or_exit();
}
v.append(&mut list);
@@ -520,9 +518,7 @@ fn show(rt: &Runtime) {
let mut instances = instance_lister_fn(&e);
{
- let _ = rt
- .report_touched(e.get_location())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(e.get_location()).unwrap_or_exit();
}
v.append(&mut instances);
@@ -582,9 +578,7 @@ fn done(rt: &Runtime) {
}
{
- let _ = rt
- .report_touched(r.get_location())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(r.get_location()).unwrap_or_exit();
}
}
diff --git a/bin/domain/imag-log/src/main.rs b/bin/domain/imag-log/src/main.rs
index 900f3e4..525eff7 100644
--- a/bin/domain/imag-log/src/main.rs
+++ b/bin/domain/imag-log/src/main.rs
@@ -171,7 +171,7 @@ fn show(rt: &Runtime) {
let _ = rt
.report_touched(entry.get_location())
- .map_err_trace_exit_unwrap(1);
+ .unwrap_or_exit();
Ok(())
})
.collect::<Result<Vec<()>, ExitCode>>()
diff --git a/bin/domain/imag-mail/src/main.rs b/bin/domain/imag-mail/src/main.rs
index 35b6236..0a7da7f 100644
--- a/bin/domain/imag-mail/src/main.rs
+++ b/bin/domain/imag-mail/src/main.rs
@@ -95,7 +95,7 @@ fn import_mail(rt: &Runtime) {
.map_info_str("Ok")
.map_err_trace_exit_unwrap(1);
- let _ = rt.report_touched(mail.fle().get_location()).map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(mail.fle().get_location()).unwrap_or_exit();
}
fn list(rt: &Runtime) {
@@ -147,7 +147,7 @@ fn list(rt: &Runtime) {
to = to
).to_exit_code().unwrap_or_exit();
- let _ = rt.report_touched(m.fle().get_location()).map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(m.fle().get_location()).unwrap_or_exit();
}
let _ = rt.store()
diff --git a/bin/domain/imag-notes/src/main.rs b/bin/domain/imag-notes/src/main.rs
index 8758cbd..2d9c03b 100644
--- a/bin/domain/imag-notes/src/main.rs
+++ b/bin/domain/imag-notes/src/main.rs
@@ -112,9 +112,7 @@ fn create(rt: &Runtime) {
.map_err_trace_exit_unwrap(1);
}
- let _ = rt
- .report_touched(note.get_location())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(note.get_location()).unwrap_or_exit();
}
fn delete(rt: &Runtime) {
@@ -136,9 +134,7 @@ fn edit(rt: &Runtime) {
.map_warn_err_str("Editing failed")
.map_err_trace_exit_unwrap(1);
- let _ = rt
- .report_touched(note.get_location())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(note.get_location()).unwrap_or_exit();
})
.unwrap_or_else(|| {
error!("Cannot find note with name '{}'", name);
@@ -170,9 +166,7 @@ fn list(rt: &Runtime) {
.to_exit_code()
.unwrap_or_exit();
- let _ = rt
- .report_touched(note.get_location())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(note.get_location()).unwrap_or_exit();
});
}
diff --git a/bin/domain/imag-timetrack/src/cont.rs b/bin/domain/imag-timetrack/src/cont.rs
index 1e88dd6..60ab955 100644
--- a/bin/domain/imag-timetrack/src/cont.rs
+++ b/bin/domain/imag-timetrack/src/cont.rs
@@ -87,8 +87,7 @@ pub fn cont(rt: &Runtime) -> i32 {
.map(|_| 0)
.map_err_trace();
- let _ = rt.report_touched(tracking.get_location())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(tracking.get_location()).unwrap_or_exit();
val
})
diff --git a/bin/domain/imag-timetrack/src/day.rs b/bin/domain/imag-timetrack/src/day.rs
index 2cff8fb..6a09904 100644
--- a/bin/domain/imag-timetrack/src/day.rs
+++ b/bin/domain/imag-timetrack/src/day.rs
@@ -103,8 +103,7 @@ pub fn day(rt: &Runtime) -> i32 {
let end = e.get_end_datetime()?;
debug!(" -> end = {:?}", end);
- let _ = rt.report_touched(e.get_location())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(e.get_location()).unwrap_or_exit();
Ok((tag, start, end))
})
diff --git a/bin/domain/imag-timetrack/src/list.rs b/bin/domain/imag-timetrack/src/list.rs
index 80019e8..2e79412 100644
--- a/bin/domain/imag-timetrack/src/list.rs
+++ b/bin/domain/imag-timetrack/src/list.rs
@@ -162,8 +162,7 @@ pub fn list_impl(rt: &Runtime,
.collect();
tab.add_row(Row::new(cells));
- let _ = rt.report_touched(e.get_location())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(e.get_location()).unwrap_or_exit();
Ok(tab)
})
diff --git a/bin/domain/imag-timetrack/src/month.rs b/bin/domain/imag-timetrack/src/month.rs
index 8e9e7f6..f5bf99d 100644
--- a/bin/domain/imag-timetrack/src/month.rs
+++ b/bin/domain/imag-timetrack/src/month.rs
@@ -118,8 +118,7 @@ pub fn month(rt: &Runtime) -> i32 {
let end = e.get_end_datetime()?;
debug!(" -> end = {:?}", end);
- let _ = rt.report_touched(e.get_location())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(e.get_location()).unwrap_or_exit(1);
Ok((tag, start, end))
})
diff --git a/bin/domain/imag-timetrack/src/start.rs b/bin/domain/imag-timetrack/src/start.rs
index ff44023..39ddea4 100644
--- a/bin/domain/imag-timetrack/src/start.rs
+++ b/bin/domain/imag-timetrack/src/start.rs
@@ -59,8 +59,7 @@ pub fn start(rt: &Runtime) -> i32 {
1
},
Ok(entry) => {
- let _ = rt.report_touched(entry.get_location())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(entry.get_location()).unwrap_or_exit();
acc
}
diff --git a/bin/domain/imag-timetrack/src/stop.rs b/bin/domain/imag-timetrack/src/stop.rs
index 2eee55f..2fc27be 100644
--- a/bin/domain/imag-timetrack/src/stop.rs
+++ b/bin/domain/imag-timetrack/src/stop.rs
@@ -98,8 +98,7 @@ pub fn stop(rt: &Runtime) -> i32 {
}
Ok(_) => {
format!("Setting end time worked: {:?}", elem);
- let _ = rt.report_touched(elem.get_location())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(elem.get_location()).unwrap_or_exit();
acc
}
}
diff --git a/bin/domain/imag-timetrack/src/track.rs b/bin/domain/imag-timetrack/src/track.rs
index c9171e1..f89047a 100644
--- a/bin/domain/imag-timetrack/src/track.rs
+++ b/bin/domain/imag-timetrack/src/track.rs
@@ -87,8 +87,7 @@ pub fn track(rt: &Runtime) -> i32 {
1
},
Ok(entry) => {
- let _ = rt.report_touched(entry.get_location())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(entry.get_location()).unwrap_or_exit();
acc
}
})
diff --git a/bin/domain/imag-timetrack/src/week.rs b/bin/domain/imag-timetrack/src/week.rs
index e003d2f..5c38403 100644
--- a/bin/domain/imag-timetrack/src/week.rs
+++ b/bin/domain/imag-timetrack/src/week.rs
@@ -116,8 +116,7 @@ pub fn week(rt: &Runtime) -> i32 {
let end = e.get_end_datetime()?;
debug!(" -> end = {:?}", end);
- let _ = rt.report_touched(e.get_location())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(e.get_location()).unwrap_or_exit();
Ok((tag, start, end))
})
diff --git a/bin/domain/imag-timetrack/src/year.rs b/bin/domain/imag-timetrack/src/year.rs
index 4bd48d2..16d3005 100644
--- a/bin/domain/imag-timetrack/src/year.rs
+++ b/bin/domain/imag-timetrack/src/year.rs
@@ -116,8 +116,7 @@ pub fn year(rt: &Runtime) -> i32 {
let end = e.get_end_datetime()?;
debug!(" -> end = {:?}", end);
- let _ = rt.report_touched(e.get_location())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(e.get_location()).unwrap_or_exit();
Ok((tag, start, end))
})
diff --git a/bin/domain/imag-wiki/src/main.rs b/bin/domain/imag-wiki/src/main.rs
index 179b300..a32960f 100644
--- a/bin/domain/imag-wiki/src/main.rs
+++ b/bin/domain/imag-wiki/src/main.rs
@@ -181,9 +181,7 @@ fn create(rt: &Runtime, wiki_name: &str) {
writeln!(lock, "{}", id).to_exit_code().unwrap_or_exit()
}
- let _ = rt
- .report_touched(&id)
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(&id).unwrap_or_exit();
}
fn create_wiki(rt: &Runtime) {
@@ -191,9 +189,7 @@ fn create_wiki(rt: &Runtime) {
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 _ = rt
- .report_touched(index.get_location())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(index.get_location()).unwrap_or_exit();
}
fn show(rt: &Runtime, wiki_name: &str) {
@@ -251,9 +247,7 @@ fn show(rt: &Runtime, wiki_name: &str) {
.to_exit_code()
.unwrap_or_exit();
- let _ = rt
- .report_touched(entry.get_location())
- .map_err_trace_exit_unwrap(1);
+ let _ = rt.report_touched(entry.get_location()).unwrap_or_exit();
}
}
diff --git a/lib/core/libimagrt/src/runtime.rs b/lib/core/libimagrt/src/runtime.rs
index 5fb367d..2466fad 100644
--- a/lib/core/libimagrt/src/runtime.rs
+++ b/lib/core/libimagrt/src/runtime.rs
@@ -25,6 +25,7 @@ use std::io::Stdin;
use std::sync::Arc;
use std::io::StdoutLock;
use std::borrow::Borrow;
+use std::result::Result as RResult;
pub use clap::App;
use clap::AppSettings;
@@ -41,8 +42,10 @@ use configuration::{fetch_config, override_config, InternalConfiguration};
use logger::ImagLogger;
use io::OutputProxy;
+use libimagerror::exit::ExitCode;
use libimagerror::errors::ErrorMsg as EM;
use libimagerror::trace::*;
+use libimagerror::io::ToExitCode;
use libimagstore::store::Store;
use libimagstore::storeid::StoreId;
use libimagstore::file_abstraction::InMemoryFileAbstraction;
@@ -573,14 +576,14 @@ impl<'a> Runtime<'a> {
.map_err(Error::from)
}
- pub fn report_touched(&self, id: &StoreId) -> Result<()> {
+ pub fn report_touched(&self, id: &StoreId) -> RResult<(), ExitCode> {
let out = ::std::io::stdout();
let mut lock = out.lock();
self.report_touched_id(id, &mut lock)
}
- pub fn report_all_touched<ID, I>(&self, ids: I) -> Result<()>
+ pub fn report_all_touched<ID, I>(&self, ids: I) -> RResult<(), ExitCode>
where ID: Borrow<StoreId> + Sized,
I: Iterator<Item = ID>
{
@@ -595,15 +598,15 @@ impl<'a> Runtime<'a> {
}
#[inline]
- fn report_touched_id(&self, id: &StoreId, output: &mut StdoutLock) -> Result<()> {
+ fn report_touched_id(&self, id: &StoreId, output: &mut StdoutLock) -> RResult<(), ExitCode> {
use std::io::Write;
if self.output_is_pipe() && !self.ignore_ids {
trace!("Reporting: {} to {:?}", id, output);
- writeln!(output, "{}", id)?;
+ writeln!(output, "{}", id).to_exit_code()
+ } else {
+ Ok(())
}
-
- Ok(())
}
}