]> git.corax.cc Git - toolbox/commitdiff
include/opt: Don't treat options with values as arrays
authorMatthias Kruk <m@m10k.eu>
Mon, 26 Dec 2022 03:55:32 +0000 (12:55 +0900)
committerMatthias Kruk <m@m10k.eu>
Mon, 26 Dec 2022 04:09:26 +0000 (13:09 +0900)
Because the bit pattern __opt_flag_is_array has more than one set
bit, it is not enough to use a bitwise and to check if an option is
an array, but that is what `opt_print_help()' does.

This commit modifies `opt_print_help()' so that it checks whether
the result of the bitwise and equals __opt_flag_is_array, avoiding
any option with a value to be treated as an array.

include/opt.sh

index bb9f222be1490c450ea361964f141c16057933fb..4d228d7bc9def61e7d607d84c96febe9c2029507 100644 (file)
@@ -149,14 +149,16 @@ opt_print_help() {
 
        for short in $(array_sort "${__opt_short[@]}"); do
                local long
+               local -i flags
 
                long="${__opt_map[-$short]}"
+               flags="${__opt_flags[$long]}"
 
                printf "\t-%s\t--%s\t%s\n" \
                       "$short" "$long" "${__opt_desc[$long]}"
-               if (( ${__opt_flags["$long"]} & __opt_flag_has_value )) &&
+               if (( flags & __opt_flag_has_value )) &&
                   array_contains "$long" "${!__opt_default[@]}"; then
-                       if (( ${__opt_flags["$long"]} & __opt_flag_is_array )); then
+                       if (( ( flags & __opt_flag_is_array ) == __opt_flag_is_array )); then
                                local -n __opt_print_help_array="${__opt_default[$long]}"
 
                                if (( ${#__opt_print_help_array[@]} > 0 )); then