refactor: 支持 0.85.0

This commit is contained in:
KAAAsS 2023-10-20 16:13:28 +08:00
parent 91efeb74b8
commit 38850ebf8e
Signed by: KAAAsS
GPG Key ID: D22F53AF662411FE
8 changed files with 21 additions and 21 deletions

View File

@ -98,19 +98,19 @@ def main [
--ignore-constraint (-C), # 忽略模块的约束检查 --ignore-constraint (-C), # 忽略模块的约束检查
] { ] {
# 家目录 # 家目录
let-env HOME_DIR = ( $env.HOME_DIR = (
if ($home_dir != null) { $home_dir } else { $env.HOME } if ($home_dir != null) { $home_dir } else { $env.HOME }
| path expand | path expand
) )
# 日志等级 # 日志等级
let-env LOG_LEVEL = ( $env.LOG_LEVEL = (
if ($verbose) { 0 } if ($verbose) { 0 }
else { if ($less) { 12 } else { 10 } } else { if ($less) { 12 } else { 10 } }
) )
# 确认选项 # 确认选项
let-env NO_CONFIRM = $no_confirm $env.NO_CONFIRM = $no_confirm
# 约束检查 # 约束检查
let-env IGNORE_CONSTRAINT = $ignore_constraint $env.IGNORE_CONSTRAINT = $ignore_constraint
# 加载配置集 # 加载配置集
active_config register active_config register
# 运行操作 # 运行操作

View File

@ -9,7 +9,7 @@ use global_conf.nu
# 注册自定义约束 # 注册自定义约束
export def-env register_custom_constraint [ export def-env register_custom_constraint [
name: string, # 约束名 name: string, # 约束名
fn: block, # 约束检查函数,返回 bool fn: closure, # 约束检查函数,返回 bool
] { ] {
log debug $"自定义约束: ($name): ($fn)" log debug $"自定义约束: ($name): ($fn)"
let constraints = (global_conf get_config "_" "constraints") let constraints = (global_conf get_config "_" "constraints")
@ -62,7 +62,7 @@ export def check_constraint [
export def check_all_constraints [] { export def check_all_constraints [] {
let constraints = (global_conf get_config "_" "constraints") let constraints = (global_conf get_config "_" "constraints")
mut result = null mut result = []
for $cons in ($constraints | transpose key).key { for $cons in ($constraints | transpose key).key {
$result = ($result | append { $result = ($result | append {
"constraint": $cons, "constraint": $cons,

View File

@ -6,7 +6,7 @@ use ../constraints.nu
export-env { export-env {
# 全局配置 # 全局配置
let-env modules_config = { "_": $env.modules_config = { "_":
{ "constraints": (constraints default_constraints) } { "constraints": (constraints default_constraints) }
} }
} }
@ -57,7 +57,7 @@ export def-env set_config [
$old_config $old_config
| merge { $config : $value } | merge { $config : $value }
) )
let-env modules_config = ( $env.modules_config = (
$modules_config $modules_config
| merge { $module : $config } | merge { $module : $config }
) )

View File

@ -36,12 +36,12 @@ export def-env register_post_install [module: string, hook: closure] {
} }
# 注册模块卸载前运行钩子 # 注册模块卸载前运行钩子
export def-env register_pre_uninstall [module: string, hook: block] { export def-env register_pre_uninstall [module: string, hook: closure] {
register_hook "pre_uninstall" $module $hook register_hook "pre_uninstall" $module $hook
} }
# 注册模块卸载后运行钩子 # 注册模块卸载后运行钩子
export def-env register_post_uninstall [module: string, hook: block] { export def-env register_post_uninstall [module: string, hook: closure] {
register_hook "post_uninstall" $module $hook register_hook "post_uninstall" $module $hook
} }

View File

@ -18,7 +18,7 @@ export def filtered_modules [
$modules $modules
} else { } else {
# 检查模块是否存在 # 检查模块是否存在
mut result = null mut result = []
for $module in $want_modules { for $module in $want_modules {
if (not ($module in $modules)) { if (not ($module in $modules)) {
log error $"模块 ($module) 不存在!" log error $"模块 ($module) 不存在!"
@ -34,7 +34,7 @@ export def filtered_modules [
if ("IGNORE_CONSTRAINT" in $env and $env.IGNORE_CONSTRAINT) { if ("IGNORE_CONSTRAINT" in $env and $env.IGNORE_CONSTRAINT) {
return $modules return $modules
} }
mut result = null mut result = []
for $module in $modules { for $module in $modules {
let constraints = (global_conf get_config $module "constraints" []) let constraints = (global_conf get_config $module "constraints" [])
let check = ( let check = (

View File

@ -21,7 +21,7 @@ def get_base_dir [local: path, dest: path] {
# 声明文件及其目标路径 # 声明文件及其目标路径
export def-env declare [ export def-env declare [
module: string, # 模块名称 module: string, # 模块名称
local: path, # 本地路径,以项目根目录为起点的相对路径 local: any, # 本地路径,以项目根目录为起点的相对路径
dest: string, # 目标路径,以用户家目录为起点的相对路径 dest: string, # 目标路径,以用户家目录为起点的相对路径
--local-only: bool, # 是否是本地特有的文件。若文件不存在则会自动从 example 创建本地文件 --local-only: bool, # 是否是本地特有的文件。若文件不存在则会自动从 example 创建本地文件
] { ] {
@ -33,7 +33,7 @@ export def-env declare [
} }
# 遍历 local 路径,获得映射 # 遍历 local 路径,获得映射
mut new_maps = null mut new_maps = []
for $local in $locals { for $local in $locals {
let dest = if ($type == "list<string>") { let dest = if ($type == "list<string>") {
# 对于文件列表(如 glob把文件名追加在最后 # 对于文件列表(如 glob把文件名追加在最后

View File

@ -3,7 +3,7 @@
# Copyright (C) 2022 KAAAsS # Copyright (C) 2022 KAAAsS
def-env confirm_loop [ prompt: string, default: string ] { def-env confirm_loop [ prompt: string, default: string ] {
let-env result = if ($env.result == null) { $env.result = if ($env.result == null) {
let got = (input $prompt) let got = (input $prompt)
if ($got == "y" or $got == "n") { if ($got == "y" or $got == "n") {
$got $got
@ -43,7 +43,7 @@ export def confirm [
$default == "y" $default == "y"
} else { } else {
# 尝试获得结果 # 尝试获得结果
let-env result = null $env.result = null
# 最多尝试 5 次(因为 nushell 的限制暂时无法在循环里编辑环境) # 最多尝试 5 次(因为 nushell 的限制暂时无法在循环里编辑环境)
confirm_loop $prompt $default confirm_loop $prompt $default
@ -67,7 +67,7 @@ def main [] {
print (confirm "测试 1") print (confirm "测试 1")
print (confirm "测试 2" "y") print (confirm "测试 2" "y")
print (confirm "测试 3" "n") print (confirm "测试 3" "n")
let-env NO_CONFIRM = true $env.NO_CONFIRM = true
print (confirm "测试 2" "y") print (confirm "测试 2" "y")
print (confirm "测试 3" "n") print (confirm "测试 3" "n")
print (confirm "测试 1") print (confirm "测试 1")

View File

@ -6,13 +6,13 @@ use pkgs/homebrew.nu
export-env { export-env {
# 所有可用的包管理器 # 所有可用的包管理器
let-env package_managers = [ $env.package_managers = [
(pacman pack), (pacman pack),
(homebrew pack), (homebrew pack),
(fallback_manager) (fallback_manager)
] ]
# 计算默认包管理器 # 计算默认包管理器
let-env default_package_manager = (select_managers) $env.default_package_manager = (select_managers)
} }
def select_managers [ def select_managers [
@ -184,7 +184,7 @@ export def test [] {
use testing * use testing *
# 增加 Mock 管理器 # 增加 Mock 管理器
let-env package_managers = [ $env.package_managers = [
{ {
"name": "unavailable", "name": "unavailable",
"available?": { false } "available?": { false }
@ -202,7 +202,7 @@ export def test [] {
"check_install?": {|p| $p == "mock2" }, "check_install?": {|p| $p == "mock2" },
} }
] ]
let-env default_package_manager = (select_managers) $env.default_package_manager = (select_managers)
# select_managers # select_managers
let mock = (select_managers "mock2") let mock = (select_managers "mock2")