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

Fix default value check for the add method

parent 38268010
Pipeline #55 passed with stage
in 21 seconds
...@@ -271,13 +271,13 @@ bashopts_declare() { ...@@ -271,13 +271,13 @@ bashopts_declare() {
if ! [[ -v options[check] ]]; then if ! [[ -v options[check] ]]; then
options[check]="bashopts_check_${options[type]}" options[check]="bashopts_check_${options[type]}"
fi fi
# Check the default value format
options[default]="$(${options[check]} "${options[default]}")" || exit 1
# format the option method # format the option method
case "${options[method]}" in case "${options[method]}" in
''|s|set) ''|s|set)
# default: simple value - override # default: simple value - override
options[method]="set" options[method]="set"
# Check the default value format
options[default]="$(${options[check]} "${options[default]}")" || exit 1
;; ;;
a|add) a|add)
# array value - add # array value - add
...@@ -401,15 +401,16 @@ bashopts_diplay_help() { ...@@ -401,15 +401,16 @@ bashopts_diplay_help() {
# display additional information the each properties # display additional information the each properties
# discarding special options like --help # discarding special options like --help
if [[ -v bashopts_optprop_expression[$op] ]]; then if [[ -v bashopts_optprop_expression[$op] ]]; then
dval="\"${bashopts_optprop_expression[$op]//\"/\\\"}\"" elts="- [\$$op] (type:${bashopts_optprop_type[$op]}, default:\"${bashopts_optprop_expression[$op]//\"/\\\"}\")"
fi elif [[ -v bashopts_optprop_default[$op] ]]; then
if [ "${bashopts_optprop_type[$op]}" == "string" ]; then if [ "${bashopts_optprop_type[$op]}" == "string" ]; then
dval=${dval:-"\"${bashopts_optprop_default[$op]//\"/\\\"}\""} 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 else
dval=${dval:-${bashopts_optprop_default[$op]}} elts="- [\$$op] (type:${bashopts_optprop_type[$op]})"
fi fi
# add type and default value info
elts="- [\$$op] (type:${bashopts_optprop_type[$op]}, default:$dval)"
fi fi
# display arguments, value if available, description, and additional info if available # 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" printf " %-${optargs_max_len}s %s\n" "${optargs[$op]}" "${bashopts_optprop_description[$op]} $elts"
......
...@@ -339,6 +339,15 @@ _test_case_22() { ...@@ -339,6 +339,15 @@ _test_case_22() {
bashopts_process_option -n value -k is_eq_to_null -r 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() { _test() {
bashopts_setup -n "$0" -d "Test case $0" 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