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>
This commit is contained in:
parent
19912f5e88
commit
f1a639ea8c
35 changed files with 75 additions and 153 deletions
|
@ -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();
|
||||
})
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<()> {
|
||||
|
|
|
@ -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"),
|
||||
};
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
});
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
});
|
||||
|
|
|
@ -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
|
||||
});
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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>>()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
})
|
||||
|
|
|
@ -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))
|
||||
})
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
|
|
|
@ -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))
|
||||
})
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
})
|
||||
|
|
|
@ -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))
|
||||
})
|
||||
|
|
|
@ -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))
|
||||
})
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue