From: Matthias Kruk Date: Mon, 26 Dec 2022 03:55:32 +0000 (+0900) Subject: include/opt: Don't treat options with values as arrays X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=a0f1a84d1b518154617ee9aa6096740d724e61bd;p=toolbox include/opt: Don't treat options with values as arrays 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. --- diff --git a/include/opt.sh b/include/opt.sh index bb9f222..4d228d7 100644 --- a/include/opt.sh +++ b/include/opt.sh @@ -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