From a6c37095f1eea72acbebebfa88bdf84f65f61f51 Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Mon, 26 Oct 2020 18:50:34 +0100 Subject: [PATCH] [type/__uci_section] Externalise functions to separate file --- .../type/__uci_section/files/functions.sh | 52 +++++++++++++++++++ cdist/conf/type/__uci_section/manifest | 42 +-------------- 2 files changed, 54 insertions(+), 40 deletions(-) create mode 100644 cdist/conf/type/__uci_section/files/functions.sh diff --git a/cdist/conf/type/__uci_section/files/functions.sh b/cdist/conf/type/__uci_section/files/functions.sh new file mode 100644 index 00000000..9f510958 --- /dev/null +++ b/cdist/conf/type/__uci_section/files/functions.sh @@ -0,0 +1,52 @@ +# -*- mode: sh; indent-tabs-mode: t -*- + +append_values() { + while read -r _value + do + set -- "$@" --value "${_value}" + done + unset _value + "$@" &2 +} + +uci_validate_name() { + # like util.c uci_validate_name() + test -n "$*" && test -z "$(printf %s "$*" | tr -d '[:alnum:]_' | tr -c '' .)" +} + +unquote_lines() { + sed -e '/^".*"$/{s/^"//;s/"$//}' \ + -e '/'"^'.*'"'$/{s/'"^'"'//;s/'"'$"'//}' +} + +validate_options() { + grep -shv -e '^[[:alnum:]_]\{1,\}=' "$@" +} diff --git a/cdist/conf/type/__uci_section/manifest b/cdist/conf/type/__uci_section/manifest index a7865315..208a2c4e 100755 --- a/cdist/conf/type/__uci_section/manifest +++ b/cdist/conf/type/__uci_section/manifest @@ -18,46 +18,8 @@ # along with cdist. If not, see . # -grep_line() { { shift; printf '%s\n' "$@"; } | grep -qxF "$1"; } -prefix_lines() { - while test $# -gt 0 - do - echo "$2" | awk -v prefix="$1" '$0 { printf "%s %s\n", prefix, $0 }' - shift; shift - done -} -uci_validate_name() { - # like util.c uci_validate_name() - test -n "$*" && test -z "$(printf %s "$*" | tr -d '[:alnum:]_' | tr -c '' .)" -} -validate_options() { grep -shv -e '^[[:alnum:]_]\{1,\}=' "$@"; } -unquote_lines() { - sed -e '/^".*"$/{s/^"//;s/"$//}' \ - -e '/'"^'.*'"'$/{s/'"^'"'//;s/'"'$"'//}' -} -append_values() { - while read -r _value - do - set -- "$@" --value "${_value}" - done - unset _value - "$@" &2 -} +# shellcheck source=files/functions.sh +. "${__type:?}/files/functions.sh" ## Check section name and error if invalid!