ddns-scripts: refactor load_all_config_options()

Same functionality - code reads less 'shouty' and 'stabby'.

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
This commit is contained in:
Paul Donald
2024-11-30 16:46:08 +01:00
committed by Florian Eckert
parent 77933a45ea
commit 2bf1916a34

View File

@@ -129,35 +129,34 @@ USE_CURL=$(uci -q get ddns.global.use_curl) || USE_CURL=0 # read config
# $1 = ddns, $2 = SECTION_ID # $1 = ddns, $2 = SECTION_ID
load_all_config_options() load_all_config_options()
{ {
local __PKGNAME="$1" local pkg_name section_id tmp_var all_opt_vars
local __SECTIONID="$2" pkg_name="$1"
local __VAR section_id="$2"
local __ALL_OPTION_VARIABLES=""
# this callback loads all the variables in the __SECTIONID section when we do # this callback loads all the variables in the $section_id section when we do
# config_load. We need to redefine the option_cb for different sections # config_load. We need to redefine the option_cb for different sections
# so that the active one isn't still active after we're done with it. For reference # so that the active one isn't still active after we're done with it. For reference
# the $1 variable is the name of the option and $2 is the name of the section # the $1 variable is the name of the option and $2 is the name of the section
config_cb() config_cb()
{ {
if [ ."$2" = ."$__SECTIONID" ]; then if [ ."$2" = ."$section_id" ]; then
option_cb() option_cb()
{ {
__ALL_OPTION_VARIABLES="$__ALL_OPTION_VARIABLES $1" all_opt_vars="$all_opt_vars $1"
} }
else else
option_cb() { return 0; } option_cb() { return 0; }
fi fi
} }
config_load "$__PKGNAME" config_load "$pkg_name"
# Given SECTION_ID not found so no data, so return 1 # Given SECTION_ID not found so no data, so return 1
[ -z "$__ALL_OPTION_VARIABLES" ] && return 1 [ -z "$all_opt_vars" ] && return 1
for __VAR in $__ALL_OPTION_VARIABLES for tmp_var in $all_opt_vars
do do
config_get "$__VAR" "$__SECTIONID" "$__VAR" config_get "$tmp_var" "$section_id" "$tmp_var"
done done
return 0 return 0
} }