diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2024-05-10 13:40:48 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-10 13:40:48 +0800 |
commit | c820d1f4e3f8cd6c56da80370044d46ba79fd85d (patch) | |
tree | ff4d8c393c3e1f238c076611f6d10437b54d2850 | |
parent | 3ead0aac05e5305fbfb8a0c1bfd7dd838a2eb793 (diff) | |
parent | c746d763425e757372dd0270ab92d0f9464ac556 (diff) | |
download | lua-language-server-c820d1f4e3f8cd6c56da80370044d46ba79fd85d.zip |
Merge pull request #2655 from carsakiller/env-args
add: load ENV variables as args
-rw-r--r-- | main.lua | 2 | ||||
-rw-r--r-- | script/config/env.lua | 67 |
2 files changed, 69 insertions, 0 deletions
@@ -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 00000000..ef5b31f2 --- /dev/null +++ b/script/config/env.lua @@ -0,0 +1,67 @@ +-- 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 +---- `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", + 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", + converter = strToBool, + }, + { + 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 + if var.converter then + value = var.converter(value) + end + + _G[var.key] = value + end +end |