Commit 432c576d authored by Emeric Verschuur's avatar Emeric Verschuur

Fix default value check for the add method

parent 38268010
Pipeline #55 passed with stage
in 21 seconds
......@@ -271,13 +271,13 @@ bashopts_declare() {
if ! [[ -v options[check] ]]; then
options[check]="bashopts_check_${options[type]}"
fi
# Check the default value format
options[default]="$(${options[check]} "${options[default]}")" || exit 1
# format the option method
case "${options[method]}" in
''|s|set)
# default: simple value - override
options[method]="set"
# Check the default value format
options[default]="$(${options[check]} "${options[default]}")" || exit 1
;;
a|add)
# array value - add
......@@ -401,15 +401,16 @@ bashopts_diplay_help() {
# display additional information the each properties
# discarding special options like --help
if [[ -v bashopts_optprop_expression[$op] ]]; then
dval="\"${bashopts_optprop_expression[$op]//\"/\\\"}\""
fi
if [ "${bashopts_optprop_type[$op]}" == "string" ]; then
dval=${dval:-"\"${bashopts_optprop_default[$op]//\"/\\\"}\""}
elts="- [\$$op] (type:${bashopts_optprop_type[$op]}, default:\"${bashopts_optprop_expression[$op]//\"/\\\"}\")"
elif [[ -v bashopts_optprop_default[$op] ]]; then
if [ "${bashopts_optprop_type[$op]}" == "string" ]; then
elts="- [\$$op] (type:${bashopts_optprop_type[$op]}, default:\"${bashopts_optprop_default[$op]//\"/\\\"}\")"
else
elts="- [\$$op] (type:${bashopts_optprop_type[$op]}, default:${bashopts_optprop_default[$op]})"
fi
else
dval=${dval:-${bashopts_optprop_default[$op]}}
elts="- [\$$op] (type:${bashopts_optprop_type[$op]})"
fi
# add type and default value info
elts="- [\$$op] (type:${bashopts_optprop_type[$op]}, default:$dval)"
fi
# display arguments, value if available, description, and additional info if available
printf " %-${optargs_max_len}s %s\n" "${optargs[$op]}" "${bashopts_optprop_description[$op]} $elts"
......
......@@ -339,6 +339,15 @@ _test_case_22() {
bashopts_process_option -n value -k is_eq_to_null -r
}
_test_case_23() {
bashopts_setup -n "$0" -d "Test case $0"
bashopts_declare -n value -l value -m add -d "A str value" -t string -k is_eq_to_null
bashopts_parse_args
bashopts_process_opts
}
_test() {
bashopts_setup -n "$0" -d "Test case $0"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment