Files
mirror/mirror.lua
CNWei 3db8945e16 refactor(mirror),feat(runtime): 支持在 mirror.lua 中通过 tools_dir 设置自定义目录;优化参数解析与 Command 构建逻辑
- 新增 Lua 动态配置 tools 目录并返回完整路径
- 将 `resolve_args` 和 `to_command` 改为接受泛型 `IntoIterator`,解耦参数来源
- 统一使用 `chain` 零拷贝合并预设参数与运行时参数,消除多余堆分配
- 提权回退分支改为直接复用 `cmd.get_args()`,修复提权时 `mr:` 别名未展开的缺陷
- 规范参数与变量命名,完善代码注释
2026-08-28 17:21:29 +08:00

73 lines
2.5 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- mirror.lua (总控制台)
-- __MIRROR_DIR__ 已经在 Rust 中注入完毕,并且是正斜杠格式 (例如 C:/Tools)
local base_dir = __MIRROR_DIR__
-- 1. 自定义局部变量,方便复用与后续维护
local python_home = base_dir .. "/tools/python39"
return {
---------------------------------------------------
-- 1. 标准相对路径 + 正斜杠拼接 (最推荐,绿色便携)
---------------------------------------------------
["numa"] = {
target = base_dir .. "/tools/numa/numa.exe",
-- 追加参数
args = { "--help" },
aliases = {},
-- 注入环境变量,使用 get_env 获取宿主机当前值
env = {
PATH = { base_dir .. "/tools/numa", get_env("PATH") }
}
},
["git"] = {
target = base_dir .. "/git/bin/git.exe",
-- 追加参数
args = { "--no-pager" },
-- 注入环境变量,使用 get_env 获取宿主机当前值
env = {
PATH = { base_dir .. "/git/bin", get_env("PATH") }
}
},
---------------------------------------------------
-- 2. Lua 原生字符串语法 [[ ]] (适合直接从 Windows 复制绝对路径)
---------------------------------------------------
["python"] = {
-- 在 [[]] 内部,\ 不需要写成 \\,直接粘贴即可
target = [[C:\Python310\python.exe]],
args = { "-B" },
-- 空字典也是合法的,等同于不设置
env = {
-- 普通字符串Rust 直接新建/覆盖该环境变量
PYTHON_HOME = python_home,
HOME = base_dir .. "/home",
-- 数组列表:将 python_home 以及 python_home/Scripts 依次拼接到 PATH 前面
PATH = {
python_home,
python_home .. "/Scripts",
get_env("PATH")
}
}
},
---------------------------------------------------
-- 3. 极简参数覆盖 (没有 args 和 env)
---------------------------------------------------
["curl"] = {
target = base_dir .. "/curl/curl.exe"
},
---------------------------------------------------
-- 4. 模块化路由 (得益于 Rust 注入的 package.path)
-- require 能够直接在当前目录 或 tools/ 目录下寻找 node.lua
-- 模块缺失时由 Rust 侧记录日志并跳过该条目(见 runtime.rs
---------------------------------------------------
["node"] = require("node"),
["npm"] = require("npm")
}