Skip to content

Commit e9e785d

Browse files
committed
entrypoint: Canonicalize boolean values when writing settings.
1 parent c5f892f commit e9e785d

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

entrypoint.sh

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ set -u
99
shopt -s extglob
1010

1111
normalize_bool() {
12-
# Returns either "True" or "False"
12+
# Returns either "True" or "False", or possibly "None" if a third argument is given
1313
local varname="$1"
1414
local raw_value="${!varname:-}"
1515
local value="${raw_value,,}" # Convert to lowercase
1616
local default="${2:-False}"
17+
local allow_none="${3:-}"
1718

1819
case "$value" in
1920
true | enable | enabled | yes | y | 1 | on)
@@ -26,8 +27,12 @@ normalize_bool() {
2627
echo "$default"
2728
;;
2829
*)
29-
echo "WARNING: Invalid boolean ('$raw_value') for '$varname'; defaulting to $default" >&2
30-
echo "$default"
30+
if [ -n "$allow_none" ] && [ "$value" = "none" ]; then
31+
echo "None"
32+
else
33+
echo "WARNING: Invalid boolean ('$raw_value') for '$varname'; defaulting to $default" >&2
34+
echo "$default"
35+
fi
3136
;;
3237
esac
3338
}
@@ -137,7 +142,15 @@ setConfigurationValue() {
137142
literal)
138143
VALUE="$1"
139144
;;
140-
bool | integer | array)
145+
bool)
146+
# Note that if any settings were explicitly set as type
147+
# "bool" (which none are at current), this would provide a
148+
# slightly confusing error message with "PROVIDED_SETTING"
149+
# in it, rather than the actual setting name.
150+
local PROVIDED_SETTING="$2"
151+
VALUE="$KEY = $(normalize_bool PROVIDED_SETTING False allow_none)"
152+
;;
153+
integer | array)
141154
VALUE="$KEY = $2"
142155
;;
143156
string)

0 commit comments

Comments
 (0)