Skip to content

Commit c820d1f

Browse files
authored
Merge pull request #2655 from carsakiller/env-args
add: load ENV variables as args
2 parents 3ead0aa + c746d76 commit c820d1f

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

main.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ local fs = require 'bee.filesystem'
22
local util = require 'utility'
33
local version = require 'version'
44

5+
require 'config.env'
6+
57
local function getValue(value)
68
if value == 'true' or value == nil then
79
value = true

script/config/env.lua

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
-- Handles loading environment arguments
2+
3+
---Convert a string to boolean
4+
---@param v string
5+
local function strToBool(v)
6+
return v == "true"
7+
end
8+
9+
---ENV args are defined here.
10+
---- `name` is the ENV arg name
11+
---- `key` is the value used to index `_G` for setting the argument
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 }[]
14+
local vars = {
15+
{
16+
name = "LLS_CHECK_LEVEL",
17+
key = "CHECKLEVEL",
18+
},
19+
{
20+
name = "LLS_CHECK_PATH",
21+
key = "CHECK",
22+
},
23+
{
24+
name = "LLS_CONFIG_PATH",
25+
key = "CONFIGPATH",
26+
},
27+
{
28+
name = "LLS_DOC_OUT_PATH",
29+
key = "DOC_OUT_PATH",
30+
},
31+
{
32+
name = "LLS_DOC_PATH",
33+
key = "DOC",
34+
},
35+
{
36+
name = "LLS_FORCE_ACCEPT_WORKSPACE",
37+
key = "FORCE_ACCEPT_WORKSPACE",
38+
converter = strToBool,
39+
},
40+
{
41+
name = "LLS_LOCALE",
42+
key = "LOCALE",
43+
},
44+
{
45+
name = "LLS_LOG_LEVEL",
46+
key = "LOGLEVEL",
47+
},
48+
{
49+
name = "LLS_LOG_PATH",
50+
key = "LOGPATH",
51+
},
52+
{
53+
name = "LLS_META_PATH",
54+
key = "METAPATH",
55+
},
56+
}
57+
58+
for _, var in ipairs(vars) do
59+
local value = os.getenv(var.name)
60+
if value then
61+
if var.converter then
62+
value = var.converter(value)
63+
end
64+
65+
_G[var.key] = value
66+
end
67+
end

0 commit comments

Comments
 (0)