Skip to content

Commit c746d76

Browse files
committed
fix: convert ENV value to bool
1 parent 4c7530e commit c746d76

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

script/config/env.lua

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
-- Handles loading environment arguments
22

3+
---Convert a string to boolean
4+
---@param v string
5+
local function strToBool(v)
6+
return v == "true"
7+
end
8+
39
---ENV args are defined here.
410
---- `name` is the ENV arg name
511
---- `key` is the value used to index `_G` for setting the argument
6-
---@type { name: string, key: string }[]
12+
---- `converter` if present, will be used to convert the string value into another type
13+
---@type { name: string, key: string, converter: fun(value: string): any }[]
714
local vars = {
815
{
916
name = "LLS_CHECK_LEVEL",
@@ -15,7 +22,7 @@ local vars = {
1522
},
1623
{
1724
name = "LLS_CONFIG_PATH",
18-
key = "CONFIGPATH"
25+
key = "CONFIGPATH",
1926
},
2027
{
2128
name = "LLS_DOC_OUT_PATH",
@@ -27,7 +34,8 @@ local vars = {
2734
},
2835
{
2936
name = "LLS_FORCE_ACCEPT_WORKSPACE",
30-
key = "FORCE_ACCEPT_WORKSPACE"
37+
key = "FORCE_ACCEPT_WORKSPACE",
38+
converter = strToBool,
3139
},
3240
{
3341
name = "LLS_LOCALE",
@@ -43,13 +51,17 @@ local vars = {
4351
},
4452
{
4553
name = "LLS_META_PATH",
46-
key = "METAPATH"
47-
}
54+
key = "METAPATH",
55+
},
4856
}
4957

5058
for _, var in ipairs(vars) do
5159
local value = os.getenv(var.name)
5260
if value then
61+
if var.converter then
62+
value = var.converter(value)
63+
end
64+
5365
_G[var.key] = value
5466
end
5567
end

0 commit comments

Comments
 (0)