feat(cli): 优化 log 子命令并引入 LogLevel 强类型解析,重构 commands.lua 注册表解析与校验逻辑
- 调整 LogLevel 的 FromStr 错误类型为 String,适配 clap 的 value_parser - log 子命令直接绑定 LogLevel 枚举,消除硬编码校验与类型转换 - 规范化日志级别更新与配置读取逻辑 - handler 类型有 Function 改为 String
This commit is contained in:
37
commands/commands.lua
Normal file
37
commands/commands.lua
Normal file
@@ -0,0 +1,37 @@
|
||||
-- commands/commands.lua
|
||||
function command(mod_path)
|
||||
-- 无论输入 "a/b/c" 还是 "a\b\c",统一替换为标准的 "a.b.c"
|
||||
local normalized = mod_path:gsub("[/\\]", ".")
|
||||
|
||||
return {
|
||||
__is_lazy_command = true,
|
||||
module = normalized
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
return {
|
||||
-- 1. 单文件子命令 (commands/use.lua)
|
||||
["use"] = {
|
||||
description = "Switch the active version of a tool",
|
||||
handler = command("use")
|
||||
},
|
||||
|
||||
-- 2. 单文件子命令 (commands/list.lua)
|
||||
["list"] = {
|
||||
description = "List available and currently activated versions",
|
||||
handler = command("list")
|
||||
},
|
||||
|
||||
-- 3. 复杂多文件子命令 (加载 commands/log/init.lua)
|
||||
["log"] = {
|
||||
description = "View or configure mirror runtime logs",
|
||||
handler = command("log")
|
||||
},
|
||||
|
||||
-- 4. 支持别名快捷映射 (例如 mr ls 等价于 mr list)
|
||||
["ls"] = {
|
||||
description = "Alias for list",
|
||||
handler = command("list")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user