[type/__uci] Allow omission of --value parameter if --state absent

This commit is contained in:
Dennis Camera 2020-06-03 14:07:10 +02:00
parent 55e7b32449
commit a09120977f
4 changed files with 15 additions and 1 deletions

View file

@ -40,6 +40,14 @@ values_is=$(uci -s -N -d "${RS}" get "${option}" 2>/dev/null) || {
exit 0 exit 0
} }
if test -f "${__object:?}/parameter/value"
then
should_file="${__object:?}/parameter/value"
else
should_file='/dev/null'
fi
# strip off trailing newline # strip off trailing newline
printf '%s' "${values_is}" \ printf '%s' "${values_is}" \
| awk ' | awk '
@ -86,4 +94,4 @@ END {
print state print state
} }
' "${__object:?}/parameter/value" RS="${RS}" - ' "${should_file}" RS="${RS}" -

View file

@ -20,6 +20,7 @@ REQUIRED PARAMETERS
------------------- -------------------
value value
The value to be set. Can be used multiple times. The value to be set. Can be used multiple times.
This parameter is allowed to be omitted if `--state` is `absent`.
Due to the way cdist handles arguments, values **must not** contain newline Due to the way cdist handles arguments, values **must not** contain newline
characters. characters.

View file

@ -43,6 +43,11 @@ changes_required=false
case ${state_should} case ${state_should}
in in
(present) (present)
test -s "${__object:?}/parameter/value" || {
echo 'The parameter --value is required.' >&2
exit 1
}
# NOTE: order is ignored so rearranged is also fine. # NOTE: order is ignored so rearranged is also fine.
in_list "${state_is}" 'present' 'rearranged' || changes_required=true in_list "${state_is}" 'present' 'rearranged' || changes_required=true
;; ;;