From f08765159ac98a6dd5927c373a9c6199db434426 Mon Sep 17 00:00:00 2001 From: Nick Chambers Date: Sun, 4 Jul 2021 04:59:50 -0500 Subject: [PATCH] Add more utility functions --- rowbot | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/rowbot b/rowbot index c4e68e2..342e149 100755 --- a/rowbot +++ b/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 )) }