]> git.corax.cc Git - toolbox/commitdiff
include/inst: Split _inst_handle_opt() to fix exit behavior
authorMatthias Kruk <m@m10k.eu>
Sat, 19 Nov 2022 11:02:26 +0000 (20:02 +0900)
committerMatthias Kruk <m@m10k.eu>
Sat, 19 Nov 2022 11:02:26 +0000 (20:02 +0900)
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.

include/inst.sh

index fe0f9caaa3cdb9082fa6866f1b8e3c49ff67588c..c96e4899792c39d299dd5852a94afd4db1ccb990 100644 (file)
@@ -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() {