refactor: 适配 0.91

This commit is contained in:
KAAAsS 2024-03-25 15:38:14 +08:00
parent c1fc8f74c7
commit ba636f0b71
Signed by: KAAAsS
GPG Key ID: D22F53AF662411FE
8 changed files with 18 additions and 19 deletions

View File

@ -5,7 +5,7 @@
# #
# > use ../knotfiles/dotfile * # > use ../knotfiles/dotfile *
# > # >
# > def-env register [] { # > def --env register [] {
# > declare "example" "example/example.yml" ".config/example.yml" # > declare "example" "example/example.yml" ".config/example.yml"
# > } # > }
# #
@ -17,6 +17,6 @@
use example_module use example_module
# 注册全部模块 # 注册全部模块
export def-env register [] { export def --env register [] {
example_module register example_module register
} }

View File

@ -10,7 +10,7 @@ export def module_name [] {
} }
# 声明模块相关的文件 # 声明模块相关的文件
export def-env declare_files [] { export def --env declare_files [] {
# 普通文件的声明。目标文件位于 ~/.config/example.yml # 普通文件的声明。目标文件位于 ~/.config/example.yml
declare (module_name) "example_module/example.yml" ".config/example.yml" declare (module_name) "example_module/example.yml" ".config/example.yml"
@ -79,7 +79,7 @@ export def post_uninstall [] {
} }
# 注册当前模块 # 注册当前模块
export def-env register [] { export def --env register [] {
declare_files declare_files
require_constraints (module_name) (constraints) require_constraints (module_name) (constraints)
require_packages (module_name) (dependencies) require_packages (module_name) (dependencies)

View File

@ -7,7 +7,7 @@ use ../log.nu
use global_conf.nu use global_conf.nu
# 注册自定义约束 # 注册自定义约束
export def-env register_custom_constraint [ export def --env register_custom_constraint [
name: string, # 约束名 name: string, # 约束名
fn: closure, # 约束检查函数,返回 bool fn: closure, # 约束检查函数,返回 bool
] { ] {
@ -19,7 +19,7 @@ export def-env register_custom_constraint [
} }
# 设置模块约束 # 设置模块约束
export def-env require_constraints [ export def --env require_constraints [
module: string, module: string,
constraints: list, constraints: list,
] { ] {

View File

@ -37,7 +37,7 @@ export def get_config [
} }
# 设置模块的专有配置 # 设置模块的专有配置
export def-env set_config [ export def --env set_config [
module: string, # 模块名 module: string, # 模块名
config: string, # 配置项 config: string, # 配置项
value # 值 value # 值

View File

@ -10,10 +10,10 @@ use global_conf.nu
use module.nu [filtered_modules] use module.nu [filtered_modules]
# 注册钩子 # 注册钩子
def-env register_hook [ def --env register_hook [
hook_type: string, # 钩子类型 hook_type: string, # 钩子类型
module: string, # 模块名称 module: string, # 模块名称
hook: closure, # 运行块 hook: closure, # 运行块
] { ] {
log debug $"注册 ($hook_type): ($module) : ($hook)" log debug $"注册 ($hook_type): ($module) : ($hook)"
@ -26,27 +26,27 @@ def-env register_hook [
} }
# 注册模块安装前运行钩子 # 注册模块安装前运行钩子
export def-env register_pre_install [module: string, hook: closure] { export def --env register_pre_install [module: string, hook: closure] {
register_hook "pre_install" $module $hook register_hook "pre_install" $module $hook
} }
# 注册模块安装后运行钩子 # 注册模块安装后运行钩子
export def-env register_post_install [module: string, hook: closure] { export def --env register_post_install [module: string, hook: closure] {
register_hook "post_install" $module $hook register_hook "post_install" $module $hook
} }
# 注册模块卸载前运行钩子 # 注册模块卸载前运行钩子
export def-env register_pre_uninstall [module: string, hook: closure] { 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: closure] { export def --env register_post_uninstall [module: string, hook: closure] {
register_hook "post_uninstall" $module $hook register_hook "post_uninstall" $module $hook
} }
# 声明包依赖 # 声明包依赖
export def-env require_packages [ export def --env require_packages [
module: string, module: string,
pkgs: list, pkgs: list,
] { ] {

View File

@ -19,11 +19,11 @@ def get_base_dir [local: path, dest: path] {
} }
# 声明文件及其目标路径 # 声明文件及其目标路径
export def-env declare [ export def --env declare [
module: string, # 模块名称 module: string, # 模块名称
local: any, # 本地路径,以项目根目录为起点的相对路径 local: any, # 本地路径,以项目根目录为起点的相对路径
dest: string, # 目标路径,以用户家目录为起点的相对路径 dest: string, # 目标路径,以用户家目录为起点的相对路径
--local-only: bool, # 是否是本地特有的文件。若文件不存在则会自动从 example 创建本地文件 --local-only, # 是否是本地特有的文件。若文件不存在则会自动从 example 创建本地文件
] { ] {
let type = ($local | describe) let type = ($local | describe)
let locals = if ($type == "list<string>") { let locals = if ($type == "list<string>") {

View File

@ -2,7 +2,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 ] {
$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") {

View File

@ -17,7 +17,7 @@ export-env {
def select_managers [ def select_managers [
manager?: string, manager?: string,
--allow-unavailable: bool --allow-unavailable
] { ] {
if ($manager == null) { if ($manager == null) {
# 选择第一个可用的包管理器 # 选择第一个可用的包管理器
@ -181,7 +181,6 @@ export def resolve_manager [
} }
export def test [] { export def test [] {
use assert
# 增加 Mock 管理器 # 增加 Mock 管理器
$env.package_managers = [ $env.package_managers = [