2020-07-25 23:39:09 +00:00
|
|
|
#!/usr/bin/env bash
|
2019-12-31 05:38:46 +00:00
|
|
|
|
|
|
|
# Requires the printing.sh helper to be sourced.
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------------------
|
|
|
|
# API
|
|
|
|
#---------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
abort() {
|
|
|
|
error "\nAborting...\n"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2021-02-11 00:44:00 +00:00
|
|
|
# Use this by setting a trap in your script, like so:
|
|
|
|
# `trap at_exit EXIT`
|
|
|
|
at_exit() {
|
|
|
|
ret=$?
|
|
|
|
if [[ $ret -gt 0 ]]; then
|
|
|
|
error "The script failed with error $ret.\n"
|
|
|
|
fi
|
|
|
|
exit "$ret"
|
|
|
|
}
|
|
|
|
|