From 880d55106d49d3ff381c97ede66b9d6d783587ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Tue, 14 May 2024 15:31:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=A0=E9=80=92=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.lua | 8 +++++--- script/config/env.lua | 5 +++++ script/ltask2/init.lua | 3 ++- script/ltask2/service/main.lua | 14 +++++++++----- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/main.lua b/main.lua index 3e62e342d..08f71d8d5 100644 --- a/main.lua +++ b/main.lua @@ -2,7 +2,7 @@ local fs = require 'bee.filesystem' local util = require 'utility' local version = require 'version' -require 'config.env' +ARG = require 'config.env' local function getValue(value) if value == 'true' or value == nil then @@ -38,7 +38,9 @@ local function loadArgs() end end if key then - _G[key:upper():gsub('-', '_')] = getValue(value) + local lkey = key:lower():gsub('-', '_') + _G[lkey] = getValue(value) + ARG[lkey] = getValue(value) end end end @@ -60,7 +62,7 @@ collectgarbage('generational', 10, 50) ---@diagnostic disable-next-line: lowercase-global log = require 'log' -log.init(ROOT, fs.path(LOGPATH) / 'startup.log') +log.init(ROOT, fs.path(LOGPATH) / 'cli.log') if LOGLEVEL then log.level = tostring(LOGLEVEL):lower() end diff --git a/script/config/env.lua b/script/config/env.lua index ef5b31f28..9f64535ec 100644 --- a/script/config/env.lua +++ b/script/config/env.lua @@ -55,6 +55,8 @@ local vars = { }, } +local env = {} + for _, var in ipairs(vars) do local value = os.getenv(var.name) if value then @@ -63,5 +65,8 @@ for _, var in ipairs(vars) do end _G[var.key] = value + env[var.key] = value end end + +return env diff --git a/script/ltask2/init.lua b/script/ltask2/init.lua index bf06096ff..4bb361fdd 100644 --- a/script/ltask2/init.lua +++ b/script/ltask2/init.lua @@ -34,7 +34,8 @@ local root_config = { LOGPATH = LOGPATH, METAPATH = METAPATH, LOGLEVEL = LOGLEVEL, - } + }, + ARG, }, }, }, diff --git a/script/ltask2/service/main.lua b/script/ltask2/service/main.lua index 02067b69c..4cc342e3c 100644 --- a/script/ltask2/service/main.lua +++ b/script/ltask2/service/main.lua @@ -1,10 +1,14 @@ local fs = require 'bee.filesystem' -local args = ... +local ENV, ARG = ... -ROOT = fs.path(args.ROOT) -LOGPATH = args.LOGPATH -METAPATH = args.METAPATH -LOGLEVEL = args.LOGLEVEL +for k, v in pairs(ARG) do + _G[k] = v +end + +ROOT = fs.path(ENV.ROOT) +LOGPATH = ENV.LOGPATH +METAPATH = ENV.METAPATH +LOGLEVEL = ENV.LOGLEVEL require 'tracy'