treewide: deprecate DRY_RUN_CMD and DRY_RUN_NULL

As a replacement, this adds the `run` helper function.
This commit is contained in:
Robert Helgesson
2024-01-13 23:15:00 +01:00
parent 6b28ab2d79
commit 4256729006
25 changed files with 125 additions and 67 deletions

View File

@@ -83,3 +83,27 @@ function _iNote() {
_i "$@"
echo -n "${normalColor}"
}
# Runs the given command on live run, otherwise prints the command to standard
# output.
#
# If given the command line option `--silence`, then the command's standard and
# error output is sent to `/dev/null` on a live run.
#
# Note, the run function is exported. I.e., it is available also to called Bash
# script.
function run() {
if [[ $1 == '--silence' ]]; then
local silence=1
shift
fi
if [[ -v DRY_RUN ]] ; then
echo "$@"
elif [[ -v silence ]] ; then
"$@" > /dev/null 2>&1
else
"$@"
fi
}
export -f run