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.
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
}
__opt_required["$long"]="$long"
fi
+ if ! (( parsed_flags & __opt_flag_has_value )); then
+ __opt_value["$long"]=0
+ fi
+
return 0
}