filter fields in functions

This commit is contained in:
2025-06-21 14:43:19 +02:00
parent 6eb5799c19
commit c6fe2df0d7

View File

@ -40,17 +40,18 @@ print_array_field() {
}
# load section content from its package function
for field in "${section_fields[@]}"; do
_load_section_content_fields_pattern="$field|$_load_section_content_fields_pattern"
done
load_section_content() {
if [[ -n $1 ]]; then
suffix="_$1"
else
suffix=""
fi
if [[ ! "$(type -t "package$suffix")" = function ]]; then return; fi
# eval only variable assignments in package function
while read -r line; do
eval "$line"
done < <(declare -f "package$suffix" | grep -E '^[[:space:]]*(declare +)?[[:alnum:]_]*=')
done < <(declare -f "package$suffix" | grep -E "^[[:space:]]*(declare +)?($_load_section_content_fields_pattern)=" | sed 's/^[[:space:]]*(declare +)?//')
}
# print fields for a section