From 4c7530e997449d5d01ca758f2bea8223e36aafc7 Mon Sep 17 00:00:00 2001 From: carsakiller Date: Fri, 10 May 2024 03:14:14 +0000 Subject: [PATCH 1/2] add: load ENV variables as args --- main.lua | 2 ++ script/config/env.lua | 55 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 script/config/env.lua diff --git a/main.lua b/main.lua index 8ecfd472f..5dfbab362 100644 --- a/main.lua +++ b/main.lua @@ -2,6 +2,8 @@ local fs = require 'bee.filesystem' local util = require 'utility' local version = require 'version' +require 'config.env' + local function getValue(value) if value == 'true' or value == nil then value = true diff --git a/script/config/env.lua b/script/config/env.lua new file mode 100644 index 000000000..163ee4042 --- /dev/null +++ b/script/config/env.lua @@ -0,0 +1,55 @@ +-- Handles loading environment arguments + +---ENV args are defined here. +---- `name` is the ENV arg name +---- `key` is the value used to index `_G` for setting the argument +---@type { name: string, key: string }[] +local vars = { + { + name = "LLS_CHECK_LEVEL", + key = "CHECKLEVEL", + }, + { + name = "LLS_CHECK_PATH", + key = "CHECK", + }, + { + name = "LLS_CONFIG_PATH", + key = "CONFIGPATH" + }, + { + name = "LLS_DOC_OUT_PATH", + key = "DOC_OUT_PATH", + }, + { + name = "LLS_DOC_PATH", + key = "DOC", + }, + { + name = "LLS_FORCE_ACCEPT_WORKSPACE", + key = "FORCE_ACCEPT_WORKSPACE" + }, + { + name = "LLS_LOCALE", + key = "LOCALE", + }, + { + name = "LLS_LOG_LEVEL", + key = "LOGLEVEL", + }, + { + name = "LLS_LOG_PATH", + key = "LOGPATH", + }, + { + name = "LLS_META_PATH", + key = "METAPATH" + } +} + +for _, var in ipairs(vars) do + local value = os.getenv(var.name) + if value then + _G[var.key] = value + end +end From c746d763425e757372dd0270ab92d0f9464ac556 Mon Sep 17 00:00:00 2001 From: carsakiller Date: Fri, 10 May 2024 03:14:15 +0000 Subject: [PATCH 2/2] fix: convert ENV value to bool --- script/config/env.lua | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/script/config/env.lua b/script/config/env.lua index 163ee4042..ef5b31f28 100644 --- a/script/config/env.lua +++ b/script/config/env.lua @@ -1,9 +1,16 @@ -- Handles loading environment arguments +---Convert a string to boolean +---@param v string +local function strToBool(v) + return v == "true" +end + ---ENV args are defined here. ---- `name` is the ENV arg name ---- `key` is the value used to index `_G` for setting the argument ----@type { name: string, key: string }[] +---- `converter` if present, will be used to convert the string value into another type +---@type { name: string, key: string, converter: fun(value: string): any }[] local vars = { { name = "LLS_CHECK_LEVEL", @@ -15,7 +22,7 @@ local vars = { }, { name = "LLS_CONFIG_PATH", - key = "CONFIGPATH" + key = "CONFIGPATH", }, { name = "LLS_DOC_OUT_PATH", @@ -27,7 +34,8 @@ local vars = { }, { name = "LLS_FORCE_ACCEPT_WORKSPACE", - key = "FORCE_ACCEPT_WORKSPACE" + key = "FORCE_ACCEPT_WORKSPACE", + converter = strToBool, }, { name = "LLS_LOCALE", @@ -43,13 +51,17 @@ local vars = { }, { name = "LLS_META_PATH", - key = "METAPATH" - } + key = "METAPATH", + }, } for _, var in ipairs(vars) do local value = os.getenv(var.name) if value then + if var.converter then + value = var.converter(value) + end + _G[var.key] = value end end