Add more utility functions

This commit is contained in:
Nick Chambers 2021-07-04 04:59:50 -05:00 committed by Nick Chambers
parent 2f01b5c44c
commit f08765159a
1 changed files with 29 additions and 0 deletions

29
rowbot
View File

@ -120,6 +120,35 @@ die() {
exit "${STATUS:-42}"
}
get_option() {
if (( $# != 2 )); then
return 1
fi
local option_name=${1//-/_}
declare -n option_var=$option_name
if [[ -v opts[$1] ]]; then
option_var=${opts[log-level]}
elif [[ ! -v $option_name ]]; then
# This variable is only used for assignment.
# shellcheck disable=SC2034
option_var=$2
fi
}
has() {
if (( $# )); then
hash "$1" 2>/dev/null
else
return 1
fi
}
is_parent() {
(( BASHPID == $$ ))
}
is_reloaded() {
[[ $RELOADED = yes ]] || (( LORE_LIVES > 1 ))
}