From 38850ebf8e787f0bdff6f60955d09b5e03dc6399 Mon Sep 17 00:00:00 2001 From: KAAAsS Date: Fri, 20 Oct 2023 16:13:28 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=94=AF=E6=8C=81=200.85.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dotfiles | 8 ++++---- knotfiles/dotfile/constraint.nu | 4 ++-- knotfiles/dotfile/global_conf.nu | 4 ++-- knotfiles/dotfile/hook.nu | 4 ++-- knotfiles/dotfile/module.nu | 4 ++-- knotfiles/dotfile/symlink.nu | 4 ++-- knotfiles/interactive.nu | 6 +++--- knotfiles/pkg.nu | 8 ++++---- 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/dotfiles b/dotfiles index 64d2cb8..a779f81 100755 --- a/dotfiles +++ b/dotfiles @@ -98,19 +98,19 @@ def main [ --ignore-constraint (-C), # 忽略模块的约束检查 ] { # 家目录 - let-env HOME_DIR = ( + $env.HOME_DIR = ( if ($home_dir != null) { $home_dir } else { $env.HOME } | path expand ) # 日志等级 - let-env LOG_LEVEL = ( + $env.LOG_LEVEL = ( if ($verbose) { 0 } 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 # 运行操作 diff --git a/knotfiles/dotfile/constraint.nu b/knotfiles/dotfile/constraint.nu index 39c2e36..9963df5 100644 --- a/knotfiles/dotfile/constraint.nu +++ b/knotfiles/dotfile/constraint.nu @@ -9,7 +9,7 @@ use global_conf.nu # 注册自定义约束 export def-env register_custom_constraint [ name: string, # 约束名 - fn: block, # 约束检查函数,返回 bool + fn: closure, # 约束检查函数,返回 bool ] { log debug $"自定义约束: ($name): ($fn)" let constraints = (global_conf get_config "_" "constraints") @@ -62,7 +62,7 @@ export def check_constraint [ export def check_all_constraints [] { let constraints = (global_conf get_config "_" "constraints") - mut result = null + mut result = [] for $cons in ($constraints | transpose key).key { $result = ($result | append { "constraint": $cons, diff --git a/knotfiles/dotfile/global_conf.nu b/knotfiles/dotfile/global_conf.nu index 13707ec..0ddc4bb 100644 --- a/knotfiles/dotfile/global_conf.nu +++ b/knotfiles/dotfile/global_conf.nu @@ -6,7 +6,7 @@ use ../constraints.nu export-env { # 全局配置 - let-env modules_config = { "_": + $env.modules_config = { "_": { "constraints": (constraints default_constraints) } } } @@ -57,7 +57,7 @@ export def-env set_config [ $old_config | merge { $config : $value } ) - let-env modules_config = ( + $env.modules_config = ( $modules_config | merge { $module : $config } ) diff --git a/knotfiles/dotfile/hook.nu b/knotfiles/dotfile/hook.nu index 8cebbf4..1349ac4 100644 --- a/knotfiles/dotfile/hook.nu +++ b/knotfiles/dotfile/hook.nu @@ -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 } # 注册模块卸载后运行钩子 -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 } diff --git a/knotfiles/dotfile/module.nu b/knotfiles/dotfile/module.nu index a284343..d0d74fe 100644 --- a/knotfiles/dotfile/module.nu +++ b/knotfiles/dotfile/module.nu @@ -18,7 +18,7 @@ export def filtered_modules [ $modules } else { # 检查模块是否存在 - mut result = null + mut result = [] for $module in $want_modules { if (not ($module in $modules)) { log error $"模块 ($module) 不存在!" @@ -34,7 +34,7 @@ export def filtered_modules [ if ("IGNORE_CONSTRAINT" in $env and $env.IGNORE_CONSTRAINT) { return $modules } - mut result = null + mut result = [] for $module in $modules { let constraints = (global_conf get_config $module "constraints" []) let check = ( diff --git a/knotfiles/dotfile/symlink.nu b/knotfiles/dotfile/symlink.nu index 55b0901..029f9cc 100644 --- a/knotfiles/dotfile/symlink.nu +++ b/knotfiles/dotfile/symlink.nu @@ -21,7 +21,7 @@ def get_base_dir [local: path, dest: path] { # 声明文件及其目标路径 export def-env declare [ module: string, # 模块名称 - local: path, # 本地路径,以项目根目录为起点的相对路径 + local: any, # 本地路径,以项目根目录为起点的相对路径 dest: string, # 目标路径,以用户家目录为起点的相对路径 --local-only: bool, # 是否是本地特有的文件。若文件不存在则会自动从 example 创建本地文件 ] { @@ -33,7 +33,7 @@ export def-env declare [ } # 遍历 local 路径,获得映射 - mut new_maps = null + mut new_maps = [] for $local in $locals { let dest = if ($type == "list") { # 对于文件列表(如 glob),把文件名追加在最后 diff --git a/knotfiles/interactive.nu b/knotfiles/interactive.nu index 6db794b..0f4b941 100644 --- a/knotfiles/interactive.nu +++ b/knotfiles/interactive.nu @@ -3,7 +3,7 @@ # Copyright (C) 2022 KAAAsS 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) if ($got == "y" or $got == "n") { $got @@ -43,7 +43,7 @@ export def confirm [ $default == "y" } else { # 尝试获得结果 - let-env result = null + $env.result = null # 最多尝试 5 次(因为 nushell 的限制暂时无法在循环里编辑环境) confirm_loop $prompt $default @@ -67,7 +67,7 @@ def main [] { print (confirm "测试 1") print (confirm "测试 2" "y") print (confirm "测试 3" "n") - let-env NO_CONFIRM = true + $env.NO_CONFIRM = true print (confirm "测试 2" "y") print (confirm "测试 3" "n") print (confirm "测试 1") diff --git a/knotfiles/pkg.nu b/knotfiles/pkg.nu index 31c959a..05cc9fa 100644 --- a/knotfiles/pkg.nu +++ b/knotfiles/pkg.nu @@ -6,13 +6,13 @@ use pkgs/homebrew.nu export-env { # 所有可用的包管理器 - let-env package_managers = [ + $env.package_managers = [ (pacman pack), (homebrew pack), (fallback_manager) ] # 计算默认包管理器 - let-env default_package_manager = (select_managers) + $env.default_package_manager = (select_managers) } def select_managers [ @@ -184,7 +184,7 @@ export def test [] { use testing * # 增加 Mock 管理器 - let-env package_managers = [ + $env.package_managers = [ { "name": "unavailable", "available?": { false } @@ -202,7 +202,7 @@ export def test [] { "check_install?": {|p| $p == "mock2" }, } ] - let-env default_package_manager = (select_managers) + $env.default_package_manager = (select_managers) # select_managers let mock = (select_managers "mock2")