Add more utility functions
This commit is contained in:
parent
2f01b5c44c
commit
f08765159a
29
rowbot
29
rowbot
|
@ -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 ))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue