From fa7ce55eb2d61dfd3a6e8056f6217a5888c2798b Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Sun, 8 Jan 2023 20:56:46 +0100 Subject: debvm-waitssh: standardize option parser An option --foo is handled by opt_foo. --- debvm-waitssh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/debvm-waitssh b/debvm-waitssh index 32db862..246db17 100755 --- a/debvm-waitssh +++ b/debvm-waitssh @@ -81,22 +81,25 @@ usage_error() { usage } +opt_help() { + # shellcheck disable=SC2317 # not dead, called as "opt_$OPTARG" + usage +} +opt_quiet() { + VERBOSITY=0 +} opt_timeout() { TOTALTIMEOUT=$1 } -opt_verbosity() { - VERBOSITY=$1 -} - while getopts :qt:-: OPTCHAR; do case "$OPTCHAR" in - q) opt_verbosity 0;; + q) opt_quiet ;; t) opt_timeout "$OPTARG" ;; -) case "$OPTARG" in - help) - usage + help|quiet) + "opt_$OPTARG" ;; timeout) test "$OPTIND" -gt "$#" && usage_error "missing argument for --$OPTARG" @@ -106,9 +109,6 @@ while getopts :qt:-: OPTCHAR; do timeout=) "opt_${OPTARG%%=*}" "${OPTARG#*=}" ;; - quiet) - opt_verbosity 0 - ;; *) usage_error "unrecognized option --$OPTARG" ;; -- cgit v1.2.3