From 8efd23d2548e1aebf0d7a36bf065ddf3c0b9dbba Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Fri, 12 Aug 2022 03:14:19 +0900 Subject: [PATCH] include/opt: Initialize value of options that don't have a value The opt module uses the value of options that aren't followed by a parameter to count how often the option was on the command line. However, in this case it never initializes the value. This commit modifies the opt module so that it initializes the value of options that are not followed by a parameter to 0. --- include/opt.sh | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/include/opt.sh b/include/opt.sh index 6bb6738..80abb52 100644 --- a/include/opt.sh +++ b/include/opt.sh @@ -39,19 +39,16 @@ __init() { declare -Axg __opt_map declare -Axg __opt_required - opt_add_arg "h" "help" "" 0 \ - "Print this text" \ - '' \ - opt_print_help - - opt_add_arg "v" "verbose" "" 0 \ - "Be more verbose" \ - '' \ - log_increase_verbosity - opt_add_arg "q" "quiet" "" 0 \ - "Be less verbose" \ - '' \ - log_decrease_verbosity + opt_add_arg "h" "help" "" 0 \ + "Print this text" \ + '' opt_print_help + + opt_add_arg "v" "verbose" "" 0 \ + "Be more verbose" \ + '' log_increase_verbosity + opt_add_arg "q" "quiet" "" 0 \ + "Be less verbose" \ + '' log_decrease_verbosity return 0 } @@ -128,6 +125,10 @@ opt_add_arg() { __opt_required["$long"]="$long" fi + if ! (( parsed_flags & __opt_flag_has_value )); then + __opt_value["$long"]=0 + fi + return 0 } -- 2.47.3