From: Matthias Kruk Date: Sat, 19 Nov 2022 11:02:26 +0000 (+0900) Subject: include/inst: Split _inst_handle_opt() to fix exit behavior X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=cf045a4227241b7cca2caa940bb048243bc5e704;p=toolbox include/inst: Split _inst_handle_opt() to fix exit behavior The handler for `--stop' and `--list' options always exits, even when the option it was invoked for was neither. This commit splits the handler into two handlers that serve only one option, avoiding the incorrect behavior. --- diff --git a/include/inst.sh b/include/inst.sh index fe0f9ca..c96e489 100644 --- a/include/inst.sh +++ b/include/inst.sh @@ -38,39 +38,26 @@ __init() { return 1 fi - opt_add_arg "l" "list" "" 0 "List running instances" '' _inst_handle_opt - opt_add_arg "s" "stop" "v" "" "Stop a running instance" '^[0-9]+$' _inst_handle_opt + opt_add_arg "l" "list" "" 0 "List running instances" '' _inst_handle_opt_list + opt_add_arg "s" "stop" "v" "" "Stop a running instance" '^[0-9]+$' _inst_handle_opt_stop return 0 } -_inst_handle_opt() { +_inst_handle_opt_stop() { local opt="$1" local arg="$2" - local ret - - ret=0 - - case "$opt" in - "stop") - if ! inst_stop "$arg" "$__inst_name"; then - ret=1 - fi - ;; - - "list") - if ! inst_list "$__inst_name"; then - ret=1 - fi - ;; + inst_stop "$arg" "$__inst_name"; then + exit "$?" +} - *) - ret=1 - ;; - esac +_inst_handle_opt_list() { + local opt="$1" + local arg="$2" - exit "$ret" + inst_list "$__inst_name" + exit "$?" } inst_list() {