Commit 9cc3ce3d authored by Emeric Verschuur's avatar Emeric Verschuur

Consider invalid default value as a non fatal error

parent f32feec7
......@@ -300,14 +300,16 @@ bashopts_declare() {
options[check]="bashopts_check_${options[type]}"
fi
# format the option method
case "${options[method]}" in
case "${options[method],,}" in
''|s|set)
# default: simple value - override
options[method]="set"
if [ "${options[type]}" != "string" ] || [[ -v options[default] ]]; then
# Check the default value format
options[default]="$(${options[check]} "${options[default]}" "${options[enum_values]}")" \
|| bashopts_log C "Invalid default value for ${options[name]} option"
if ! options[default]="$(${options[check]} "${options[default]}" "${options[enum_values]}")"; then
bashopts_log W "Invalid default value for ${options[name]} option, this value will stay unset"
unset options[default]
fi
fi
;;
a|add)
......
......@@ -407,6 +407,14 @@ _test_case_28() {
req_test_eq "$(bashopts_get_valid_value_list --value | tr '\n' '#')" '"one"#"two"#"tree"#'
}
_test_case_29() {
bashopts_setup -n "$0" -d "Test case $0"
req_test_eq "$(bashopts_declare -n value -l value -d "A str value" -t number \
-v "invalid default value" 2>&1 >/dev/null | grep '^\[WARN')" \
"[WARN] Invalid default value for value option, this value will stay unset"
}
_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