When the caller attempts to redefine an option, `opt_add_arg()` fails
without printing an error message, leaving the situation undetected
if the caller does not check the return value of the call.
This commit modifies `opt_add_arg()` to print an error message when
a caller attempts to redefine an option.
return 0
}
+_opt_is_defined() {
+ local options=("$@")
+
+ local option
+
+ for option in "${options[@]}"; do
+ if [[ -n "${__opt_map[$option]}" ]]; then
+ log_error "Option \"$option\" was already declared"
+ return 0
+ fi
+ done
+
+ return 1
+}
+
opt_add_arg() {
local short="$1"
local long="$2"
local bflags
local i
- if array_contains "$short" "${__opt_short[@]}" ||
- array_contains "$long" "${__opt_long[@]}"; then
+ if _opt_is_defined "-$short" "--$long"; then
return 1
fi