Skip to content

Commit

Permalink
传递参数
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed May 14, 2024
1 parent fe512ba commit 880d551
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
8 changes: 5 additions & 3 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions script/config/env.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ local vars = {
},
}

local env = {}

for _, var in ipairs(vars) do
local value = os.getenv(var.name)
if value then
Expand All @@ -63,5 +65,8 @@ for _, var in ipairs(vars) do
end

_G[var.key] = value
env[var.key] = value
end
end

return env
3 changes: 2 additions & 1 deletion script/ltask2/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ local root_config = {
LOGPATH = LOGPATH,
METAPATH = METAPATH,
LOGLEVEL = LOGLEVEL,
}
},
ARG,
},
},
},
Expand Down
14 changes: 9 additions & 5 deletions script/ltask2/service/main.lua
Original file line number Diff line number Diff line change
@@ -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'

Expand Down

0 comments on commit 880d551

Please sign in to comment.