1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-08 11:36:05 +01:00

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
No known key found for this signature in database
GPG key ID: 96E745BD17AA17ED
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