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())
|
.set_coordinates(c.clone())
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap(1);
|
||||||
|
|
||||||
let _ = rt
|
let _ = rt.report_touched(&id).unwrap_or_exit();
|
||||||
.report_touched(&id)
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,9 +173,7 @@ fn remove(rt: &Runtime) {
|
||||||
let _ = writeln!(rt.stdout(), "{}", removed_value).to_exit_code().unwrap_or_exit();
|
let _ = writeln!(rt.stdout(), "{}", removed_value).to_exit_code().unwrap_or_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = rt
|
let _ = rt.report_touched(&id).unwrap_or_exit();
|
||||||
.report_touched(&id)
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,9 +200,7 @@ fn get(rt: &Runtime) {
|
||||||
|
|
||||||
let _ = writeln!(stdout, "{}", value).to_exit_code().unwrap_or_exit();
|
let _ = writeln!(stdout, "{}", value).to_exit_code().unwrap_or_exit();
|
||||||
|
|
||||||
let _ = rt
|
let _ = rt.report_touched(&id).unwrap_or_exit();
|
||||||
.report_touched(&id)
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,8 +125,6 @@ fn show(rt: &Runtime, e: &Entry, re: &Regex, opts: &Options, count: &mut usize)
|
||||||
*count += 1;
|
*count += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = rt
|
let _ = rt.report_touched(e.get_location()).unwrap_or_exit();
|
||||||
.report_touched(e.get_location())
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -127,11 +127,12 @@ fn main() {
|
||||||
trace!("Got output: {:?}", stdout);
|
trace!("Got output: {:?}", stdout);
|
||||||
|
|
||||||
iterator.for_each(|id| {
|
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() {
|
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(1);
|
||||||
trace!("Writing to {:?}", stdout);
|
trace!("Writing to {:?}", stdout);
|
||||||
let _ = writeln!(stdout, "{}", id)
|
writeln!(stdout, "{}", id)
|
||||||
.to_exit_code()
|
.to_exit_code()
|
||||||
.unwrap_or_exit();
|
.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)
|
.map_err_trace_exit_unwrap(1)
|
||||||
.into_iter();
|
.into_iter();
|
||||||
|
|
||||||
let _ = rt.report_all_touched(iter).map_err_trace_exit_unwrap(1);
|
let _ = rt.report_all_touched(iter).unwrap_or_exit();
|
||||||
} else {
|
} else {
|
||||||
debug!("Linking internally: {:?} -> {:?}", from, entry);
|
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)
|
.add_internal_link(&mut to_entry)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap(1);
|
||||||
|
|
||||||
let _ = rt
|
let _ = rt.report_touched(to_entry.get_location()).unwrap_or_exit();
|
||||||
.report_touched(to_entry.get_location())
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
info!("Ok: {} -> {}", from, entry);
|
info!("Ok: {} -> {}", from, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = rt
|
let _ = rt.report_touched(from_entry.get_location()).unwrap_or_exit();
|
||||||
.report_touched(from_entry.get_location())
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_linking(rt: &Runtime) {
|
fn remove_linking(rt: &Runtime) {
|
||||||
|
@ -226,9 +222,7 @@ fn remove_linking(rt: &Runtime) {
|
||||||
.remove_internal_link(&mut from)
|
.remove_internal_link(&mut from)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap(1);
|
||||||
|
|
||||||
let _ = rt
|
let _ = rt.report_touched(to_entry.get_location()).unwrap_or_exit();
|
||||||
.report_touched(to_entry.get_location())
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
},
|
},
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
// looks like this is not an entry, but a filesystem URI and therefor an
|
// 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
|
let _ = rt.report_touched(from.get_location()).unwrap_or_exit();
|
||||||
.report_touched(from.get_location())
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unlink(rt: &Runtime) {
|
fn unlink(rt: &Runtime) {
|
||||||
|
@ -267,9 +259,7 @@ fn unlink(rt: &Runtime) {
|
||||||
.unlink(rt.store())
|
.unlink(rt.store())
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap(1);
|
||||||
|
|
||||||
let _ = rt
|
let _ = rt.report_touched(&id).unwrap_or_exit();
|
||||||
.report_touched(&id)
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,18 +313,14 @@ fn list_linkings(rt: &Runtime) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = rt
|
let _ = rt.report_touched(entry.get_location()).unwrap_or_exit();
|
||||||
.report_touched(entry.get_location())
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
|
|
||||||
},
|
},
|
||||||
Ok(None) => warn!("Not found: {}", id),
|
Ok(None) => warn!("Not found: {}", id),
|
||||||
Err(e) => trace_error(&e),
|
Err(e) => trace_error(&e),
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = rt
|
let _ = rt.report_touched(&id).unwrap_or_exit();
|
||||||
.report_touched(&id)
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if !list_plain {
|
if !list_plain {
|
||||||
|
|
|
@ -52,6 +52,7 @@ use std::path::PathBuf;
|
||||||
use libimagrt::setup::generate_runtime_setup;
|
use libimagrt::setup::generate_runtime_setup;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
use libimagerror::iter::TraceIterator;
|
use libimagerror::iter::TraceIterator;
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
use libimagstore::storeid::StoreId;
|
use libimagstore::storeid::StoreId;
|
||||||
use libimagstore::store::Store;
|
use libimagstore::store::Store;
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
|
@ -131,8 +132,7 @@ fn main() {
|
||||||
})
|
})
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap(1);
|
||||||
|
|
||||||
let _ = rt.report_touched(&destname)
|
let _ = rt.report_touched(&destname).unwrap_or_exit();
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
|
|
||||||
// re-add links to moved entry
|
// re-add links to moved entry
|
||||||
relink(rt.store(), destname, &mut linked_entries);
|
relink(rt.store(), destname, &mut linked_entries);
|
||||||
|
|
|
@ -102,7 +102,7 @@ fn deref(rt: &Runtime) {
|
||||||
.map(|s| info!("{}", s))
|
.map(|s| info!("{}", s))
|
||||||
.ok(); // safe here because we exited already in the error case
|
.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 => {
|
None => {
|
||||||
error!("No entry for id '{}' found", id);
|
error!("No entry for id '{}' found", id);
|
||||||
|
|
|
@ -63,7 +63,7 @@ pub fn create(rt: &Runtime) {
|
||||||
}
|
}
|
||||||
.map_err_trace_exit_unwrap(1);
|
.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<()> {
|
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) {
|
let _ = match rt.store().get(path.clone()).map_err_trace_exit_unwrap(1) {
|
||||||
Some(entry) => {
|
Some(entry) => {
|
||||||
print_entry(rt, scmd, 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"),
|
None => info!("No entry found"),
|
||||||
};
|
};
|
||||||
|
|
|
@ -48,7 +48,7 @@ pub fn retrieve(rt: &Runtime) {
|
||||||
.map_dbg(|e| format!("{:?}", e))
|
.map_dbg(|e| format!("{:?}", e))
|
||||||
.map_err_trace_exit_unwrap(1);
|
.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");
|
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());
|
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
|
status
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -157,9 +157,7 @@ fn alter(rt: &Runtime, path: StoreId, add: Option<Vec<Tag>>, rem: Option<Vec<Tag
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = rt
|
let _ = rt.report_touched(&path).unwrap_or_exit();
|
||||||
.report_touched(&path)
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn list(path: StoreId, rt: &Runtime) {
|
fn list(path: StoreId, rt: &Runtime) {
|
||||||
|
@ -207,9 +205,7 @@ fn list(path: StoreId, rt: &Runtime) {
|
||||||
.unwrap_or_exit();
|
.unwrap_or_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = rt
|
let _ = rt.report_touched(&path).unwrap_or_exit();
|
||||||
.report_touched(&path)
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the tags which should be added from the commandline
|
/// Get the tags which should be added from the commandline
|
||||||
|
|
|
@ -98,8 +98,7 @@ fn main() {
|
||||||
let files = entries
|
let files = entries
|
||||||
.map(|entry| {
|
.map(|entry| {
|
||||||
let tmpfile = create_tempfile_for(&entry, view_header, hide_content);
|
let tmpfile = create_tempfile_for(&entry, view_header, hide_content);
|
||||||
rt.report_touched(entry.get_location())
|
rt.report_touched(entry.get_location()).unwrap_or_exit();
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
tmpfile
|
tmpfile
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
@ -209,8 +208,7 @@ fn main() {
|
||||||
.view_entry(&entry, &mut outlock)
|
.view_entry(&entry, &mut outlock)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap(1);
|
||||||
|
|
||||||
rt.report_touched(entry.get_location())
|
rt.report_touched(entry.get_location()).unwrap_or_exit();
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
let mut viewer = StdoutViewer::new(view_header, !hide_content);
|
let mut viewer = StdoutViewer::new(view_header, !hide_content);
|
||||||
|
@ -244,8 +242,7 @@ fn main() {
|
||||||
.view_entry(&entry, &mut outlock)
|
.view_entry(&entry, &mut outlock)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap(1);
|
||||||
|
|
||||||
rt.report_touched(entry.get_location())
|
rt.report_touched(entry.get_location()).unwrap_or_exit();
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,18 +101,14 @@ fn add(rt: &Runtime) {
|
||||||
.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(1);
|
||||||
|
|
||||||
let _ = rt
|
let _ = rt.report_touched(collection.get_location()).unwrap_or_exit();
|
||||||
.report_touched(collection.get_location())
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
|
|
||||||
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(1);
|
||||||
|
|
||||||
let _ = rt
|
let _ = rt.report_all_touched(new_ids.into_iter()).unwrap_or_exit();
|
||||||
.report_all_touched(new_ids.into_iter())
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("Ready");
|
info!("Ready");
|
||||||
|
@ -124,7 +120,7 @@ fn collection(rt: &Runtime) {
|
||||||
if scmd.is_present("add") { // adding a new collection
|
if scmd.is_present("add") { // adding a new collection
|
||||||
let name = scmd.value_of("add").unwrap();
|
let name = scmd.value_of("add").unwrap();
|
||||||
if let Ok(id) = BookmarkCollectionStore::new(rt.store(), &name) {
|
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);
|
info!("Created: {}", name);
|
||||||
} else {
|
} else {
|
||||||
warn!("Creating collection {} failed", name);
|
warn!("Creating collection {} failed", name);
|
||||||
|
@ -151,9 +147,7 @@ fn list(rt: &Runtime) {
|
||||||
.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(1);
|
||||||
|
|
||||||
let _ = rt
|
let _ = rt.report_touched(collection.get_location()).unwrap_or_exit();
|
||||||
.report_touched(collection.get_location())
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
|
|
||||||
collection
|
collection
|
||||||
.links(rt.store())
|
.links(rt.store())
|
||||||
|
@ -177,18 +171,14 @@ fn remove(rt: &Runtime) {
|
||||||
.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(1);
|
||||||
|
|
||||||
let _ = rt
|
let _ = rt.report_touched(collection.get_location()).unwrap_or_exit();
|
||||||
.report_touched(collection.get_location())
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
|
|
||||||
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(1);
|
||||||
|
|
||||||
let _ = rt
|
let _ = rt.report_all_touched(removed_links.into_iter()).unwrap_or_exit();
|
||||||
.report_all_touched(removed_links.into_iter())
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("Ready");
|
info!("Ready");
|
||||||
|
|
|
@ -204,8 +204,7 @@ pub fn create(rt: &Runtime) {
|
||||||
.create_from_path(&location)
|
.create_from_path(&location)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap(1);
|
||||||
|
|
||||||
let _ = rt.report_touched(entry.get_location())
|
let _ = rt.report_touched(entry.get_location()).unwrap_or_exit();
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
|
|
||||||
info!("Created entry in store");
|
info!("Created entry in store");
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -125,8 +125,7 @@ fn list(rt: &Runtime) {
|
||||||
.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(1)
|
||||||
.map(|fle| {
|
.map(|fle| {
|
||||||
let _ = rt.report_touched(fle.get_location())
|
let _ = rt.report_touched(fle.get_location()).unwrap_or_exit();
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
fle
|
fle
|
||||||
})
|
})
|
||||||
.map(|e| e.deser())
|
.map(|e| e.deser())
|
||||||
|
@ -171,9 +170,7 @@ fn import(rt: &Runtime) {
|
||||||
.retrieve_from_path(&path)
|
.retrieve_from_path(&path)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap(1);
|
||||||
|
|
||||||
let _ = rt
|
let _ = rt.report_touched(entry.get_location()).unwrap_or_exit();
|
||||||
.report_touched(entry.get_location())
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
} 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
|
||||||
|
@ -187,9 +184,7 @@ fn import(rt: &Runtime) {
|
||||||
.retrieve_from_path(&pb)
|
.retrieve_from_path(&pb)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap(1);
|
||||||
|
|
||||||
let _ = rt
|
let _ = rt.report_touched(fle.get_location()).unwrap_or_exit();
|
||||||
.report_touched(fle.get_location())
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
info!("Imported: {}", entry.path().to_str().unwrap_or("<non UTF-8 path>"));
|
info!("Imported: {}", entry.path().to_str().unwrap_or("<non UTF-8 path>"));
|
||||||
} else {
|
} else {
|
||||||
warn!("Ignoring non-file: {}", entry.path().to_str().unwrap_or("<non UTF-8 path>"));
|
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
|
.unwrap() // exited above
|
||||||
.starts_with(&hash)
|
.starts_with(&hash)
|
||||||
{
|
{
|
||||||
let _ = rt
|
let _ = rt.report_touched(entry.get_location()).unwrap_or_exit();
|
||||||
.report_touched(entry.get_location())
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
Some(deser)
|
Some(deser)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -285,9 +278,7 @@ fn find(rt: &Runtime) {
|
||||||
|| card.fullname().iter().any(|a| str_contains_any(a, &grepstring));
|
|| card.fullname().iter().any(|a| str_contains_any(a, &grepstring));
|
||||||
|
|
||||||
if take {
|
if take {
|
||||||
let _ = rt
|
let _ = rt.report_touched(entry.get_location()).unwrap_or_exit();
|
||||||
.report_touched(entry.get_location())
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
|
|
||||||
// optimization so we don't have to parse again in the next step
|
// optimization so we don't have to parse again in the next step
|
||||||
Some((entry, card))
|
Some((entry, card))
|
||||||
|
|
|
@ -45,7 +45,7 @@ pub fn create(rt: &Runtime) {
|
||||||
|
|
||||||
let mut entry = create_entry(rt.store(), &diaryname, rt);
|
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") {
|
let res = if rt.cli().subcommand_matches("create").unwrap().is_present("no-edit") {
|
||||||
debug!("Not editing new diary entry");
|
debug!("Not editing new diary entry");
|
||||||
|
|
|
@ -66,9 +66,7 @@ pub fn delete(rt: &Runtime) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = rt
|
let _ = rt.report_touched(&to_del_location).unwrap_or_exit();
|
||||||
.report_touched(&to_del_location)
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
|
|
||||||
let _ = rt
|
let _ = rt
|
||||||
.store()
|
.store()
|
||||||
|
|
|
@ -55,9 +55,7 @@ pub fn list(rt: &Runtime) {
|
||||||
.map(IntoStoreId::into_storeid)
|
.map(IntoStoreId::into_storeid)
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit(1)
|
||||||
.for_each(|id| {
|
.for_each(|id| {
|
||||||
let _ = rt
|
let _ = rt.report_touched(&id).unwrap_or_exit();
|
||||||
.report_touched(&id)
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
|
|
||||||
writeln!(rt.stdout(), "{}", id).to_exit_code().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 entries = entries.map(|e| {
|
||||||
let _ = rt
|
let _ = rt.report_touched(e.get_location()).unwrap_or_exit();
|
||||||
.report_touched(e.get_location())
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
|
|
||||||
e
|
e
|
||||||
});
|
});
|
||||||
|
|
|
@ -155,7 +155,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(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) {
|
fn delete(rt: &Runtime) {
|
||||||
|
@ -441,9 +441,7 @@ fn list(rt: &Runtime) {
|
||||||
let mut list = lister_fn(&e);
|
let mut list = lister_fn(&e);
|
||||||
|
|
||||||
{
|
{
|
||||||
let _ = rt
|
let _ = rt.report_touched(e.get_location()).unwrap_or_exit();
|
||||||
.report_touched(e.get_location())
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
v.append(&mut list);
|
v.append(&mut list);
|
||||||
|
@ -520,9 +518,7 @@ fn show(rt: &Runtime) {
|
||||||
let mut instances = instance_lister_fn(&e);
|
let mut instances = instance_lister_fn(&e);
|
||||||
|
|
||||||
{
|
{
|
||||||
let _ = rt
|
let _ = rt.report_touched(e.get_location()).unwrap_or_exit();
|
||||||
.report_touched(e.get_location())
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
v.append(&mut instances);
|
v.append(&mut instances);
|
||||||
|
@ -582,9 +578,7 @@ fn done(rt: &Runtime) {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
let _ = rt
|
let _ = rt.report_touched(r.get_location()).unwrap_or_exit();
|
||||||
.report_touched(r.get_location())
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,7 +171,7 @@ fn show(rt: &Runtime) {
|
||||||
|
|
||||||
let _ = rt
|
let _ = rt
|
||||||
.report_touched(entry.get_location())
|
.report_touched(entry.get_location())
|
||||||
.map_err_trace_exit_unwrap(1);
|
.unwrap_or_exit();
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
.collect::<Result<Vec<()>, ExitCode>>()
|
.collect::<Result<Vec<()>, ExitCode>>()
|
||||||
|
|
|
@ -95,7 +95,7 @@ fn import_mail(rt: &Runtime) {
|
||||||
.map_info_str("Ok")
|
.map_info_str("Ok")
|
||||||
.map_err_trace_exit_unwrap(1);
|
.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) {
|
fn list(rt: &Runtime) {
|
||||||
|
@ -147,7 +147,7 @@ fn list(rt: &Runtime) {
|
||||||
to = to
|
to = to
|
||||||
).to_exit_code().unwrap_or_exit();
|
).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()
|
let _ = rt.store()
|
||||||
|
|
|
@ -112,9 +112,7 @@ fn create(rt: &Runtime) {
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = rt
|
let _ = rt.report_touched(note.get_location()).unwrap_or_exit();
|
||||||
.report_touched(note.get_location())
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn delete(rt: &Runtime) {
|
fn delete(rt: &Runtime) {
|
||||||
|
@ -136,9 +134,7 @@ fn edit(rt: &Runtime) {
|
||||||
.map_warn_err_str("Editing failed")
|
.map_warn_err_str("Editing failed")
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap(1);
|
||||||
|
|
||||||
let _ = rt
|
let _ = rt.report_touched(note.get_location()).unwrap_or_exit();
|
||||||
.report_touched(note.get_location())
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
error!("Cannot find note with name '{}'", name);
|
error!("Cannot find note with name '{}'", name);
|
||||||
|
@ -170,9 +166,7 @@ fn list(rt: &Runtime) {
|
||||||
.to_exit_code()
|
.to_exit_code()
|
||||||
.unwrap_or_exit();
|
.unwrap_or_exit();
|
||||||
|
|
||||||
let _ = rt
|
let _ = rt.report_touched(note.get_location()).unwrap_or_exit();
|
||||||
.report_touched(note.get_location())
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -87,8 +87,7 @@ pub fn cont(rt: &Runtime) -> i32 {
|
||||||
.map(|_| 0)
|
.map(|_| 0)
|
||||||
.map_err_trace();
|
.map_err_trace();
|
||||||
|
|
||||||
let _ = rt.report_touched(tracking.get_location())
|
let _ = rt.report_touched(tracking.get_location()).unwrap_or_exit();
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
|
|
||||||
val
|
val
|
||||||
})
|
})
|
||||||
|
|
|
@ -103,8 +103,7 @@ pub fn day(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())
|
let _ = rt.report_touched(e.get_location()).unwrap_or_exit();
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
|
|
||||||
Ok((tag, start, end))
|
Ok((tag, start, end))
|
||||||
})
|
})
|
||||||
|
|
|
@ -162,8 +162,7 @@ pub fn list_impl(rt: &Runtime,
|
||||||
.collect();
|
.collect();
|
||||||
tab.add_row(Row::new(cells));
|
tab.add_row(Row::new(cells));
|
||||||
|
|
||||||
let _ = rt.report_touched(e.get_location())
|
let _ = rt.report_touched(e.get_location()).unwrap_or_exit();
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
|
|
||||||
Ok(tab)
|
Ok(tab)
|
||||||
})
|
})
|
||||||
|
|
|
@ -118,8 +118,7 @@ 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())
|
let _ = rt.report_touched(e.get_location()).unwrap_or_exit(1);
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
|
|
||||||
Ok((tag, start, end))
|
Ok((tag, start, end))
|
||||||
})
|
})
|
||||||
|
|
|
@ -59,8 +59,7 @@ pub fn start(rt: &Runtime) -> i32 {
|
||||||
1
|
1
|
||||||
},
|
},
|
||||||
Ok(entry) => {
|
Ok(entry) => {
|
||||||
let _ = rt.report_touched(entry.get_location())
|
let _ = rt.report_touched(entry.get_location()).unwrap_or_exit();
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
|
|
||||||
acc
|
acc
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,8 +98,7 @@ pub fn stop(rt: &Runtime) -> i32 {
|
||||||
}
|
}
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
format!("Setting end time worked: {:?}", elem);
|
format!("Setting end time worked: {:?}", elem);
|
||||||
let _ = rt.report_touched(elem.get_location())
|
let _ = rt.report_touched(elem.get_location()).unwrap_or_exit();
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
acc
|
acc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,8 +87,7 @@ pub fn track(rt: &Runtime) -> i32 {
|
||||||
1
|
1
|
||||||
},
|
},
|
||||||
Ok(entry) => {
|
Ok(entry) => {
|
||||||
let _ = rt.report_touched(entry.get_location())
|
let _ = rt.report_touched(entry.get_location()).unwrap_or_exit();
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
acc
|
acc
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -116,8 +116,7 @@ pub fn week(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())
|
let _ = rt.report_touched(e.get_location()).unwrap_or_exit();
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
|
|
||||||
Ok((tag, start, end))
|
Ok((tag, start, end))
|
||||||
})
|
})
|
||||||
|
|
|
@ -116,8 +116,7 @@ pub fn year(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())
|
let _ = rt.report_touched(e.get_location()).unwrap_or_exit();
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
|
|
||||||
Ok((tag, start, end))
|
Ok((tag, start, end))
|
||||||
})
|
})
|
||||||
|
|
|
@ -181,9 +181,7 @@ fn create(rt: &Runtime, wiki_name: &str) {
|
||||||
writeln!(lock, "{}", id).to_exit_code().unwrap_or_exit()
|
writeln!(lock, "{}", id).to_exit_code().unwrap_or_exit()
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = rt
|
let _ = rt.report_touched(&id).unwrap_or_exit();
|
||||||
.report_touched(&id)
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_wiki(rt: &Runtime) {
|
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 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(1);
|
||||||
|
|
||||||
let _ = rt
|
let _ = rt.report_touched(index.get_location()).unwrap_or_exit();
|
||||||
.report_touched(index.get_location())
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn show(rt: &Runtime, wiki_name: &str) {
|
fn show(rt: &Runtime, wiki_name: &str) {
|
||||||
|
@ -251,9 +247,7 @@ fn show(rt: &Runtime, wiki_name: &str) {
|
||||||
.to_exit_code()
|
.to_exit_code()
|
||||||
.unwrap_or_exit();
|
.unwrap_or_exit();
|
||||||
|
|
||||||
let _ = rt
|
let _ = rt.report_touched(entry.get_location()).unwrap_or_exit();
|
||||||
.report_touched(entry.get_location())
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ use std::io::Stdin;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::io::StdoutLock;
|
use std::io::StdoutLock;
|
||||||
use std::borrow::Borrow;
|
use std::borrow::Borrow;
|
||||||
|
use std::result::Result as RResult;
|
||||||
|
|
||||||
pub use clap::App;
|
pub use clap::App;
|
||||||
use clap::AppSettings;
|
use clap::AppSettings;
|
||||||
|
@ -41,8 +42,10 @@ use configuration::{fetch_config, override_config, InternalConfiguration};
|
||||||
use logger::ImagLogger;
|
use logger::ImagLogger;
|
||||||
use io::OutputProxy;
|
use io::OutputProxy;
|
||||||
|
|
||||||
|
use libimagerror::exit::ExitCode;
|
||||||
use libimagerror::errors::ErrorMsg as EM;
|
use libimagerror::errors::ErrorMsg as EM;
|
||||||
use libimagerror::trace::*;
|
use libimagerror::trace::*;
|
||||||
|
use libimagerror::io::ToExitCode;
|
||||||
use libimagstore::store::Store;
|
use libimagstore::store::Store;
|
||||||
use libimagstore::storeid::StoreId;
|
use libimagstore::storeid::StoreId;
|
||||||
use libimagstore::file_abstraction::InMemoryFileAbstraction;
|
use libimagstore::file_abstraction::InMemoryFileAbstraction;
|
||||||
|
@ -573,14 +576,14 @@ impl<'a> Runtime<'a> {
|
||||||
.map_err(Error::from)
|
.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 out = ::std::io::stdout();
|
||||||
let mut lock = out.lock();
|
let mut lock = out.lock();
|
||||||
|
|
||||||
self.report_touched_id(id, &mut 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,
|
where ID: Borrow<StoreId> + Sized,
|
||||||
I: Iterator<Item = ID>
|
I: Iterator<Item = ID>
|
||||||
{
|
{
|
||||||
|
@ -595,15 +598,15 @@ impl<'a> Runtime<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[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;
|
use std::io::Write;
|
||||||
|
|
||||||
if self.output_is_pipe() && !self.ignore_ids {
|
if self.output_is_pipe() && !self.ignore_ids {
|
||||||
trace!("Reporting: {} to {:?}", id, output);
|
trace!("Reporting: {} to {:?}", id, output);
|
||||||
writeln!(output, "{}", id)?;
|
writeln!(output, "{}", id).to_exit_code()
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue