From 350e67a8bb4171211c0193d15320bdb3032469e9 Mon Sep 17 00:00:00 2001 From: lihan Date: Sun, 28 Apr 2024 14:18:17 +0800 Subject: [PATCH] fix: prefix match is not quite correct. fix #229 --- docs/plugins/create/howto.md | 4 ++++ docs/zh-hans/plugins/create/howto.md | 4 ++++ internal/sdk.go | 8 ++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/plugins/create/howto.md b/docs/plugins/create/howto.md index 74386aee..a891c88a 100644 --- a/docs/plugins/create/howto.md +++ b/docs/plugins/create/howto.md @@ -153,6 +153,10 @@ end ## Optional hook functions +::: warning +You must delete the corresponding `.lua` file if you do not need these hook functions! +::: + ### PostInstall This hook function is called after the `PreInstall` function is executed. It is used to execute additional operations, diff --git a/docs/zh-hans/plugins/create/howto.md b/docs/zh-hans/plugins/create/howto.md index 51ae6dd4..f04b29a2 100644 --- a/docs/zh-hans/plugins/create/howto.md +++ b/docs/zh-hans/plugins/create/howto.md @@ -147,6 +147,10 @@ end ## 可选钩子函数 +::: warning +如果不需要这些钩子函数,请**删除对应的`.lua`文件**! +::: + ### PostInstall 拓展点,在`PreInstall`执行之后调用,用于执行额外的操作, 如编译源码等。根据需要实现。 diff --git a/internal/sdk.go b/internal/sdk.go index 0e950a5d..5dcabd9f 100644 --- a/internal/sdk.go +++ b/internal/sdk.go @@ -254,9 +254,10 @@ func (b *Sdk) PreUse(version Version, scope UseScope) (Version, error) { installedVersions = append(installedVersions, string(sdk.Main.Version)) } sort.Sort(installedVersions) - prefix := string(version) + version := string(version) + prefix := version + "." for _, v := range installedVersions { - if prefix == v { + if version == v { newVersion = Version(v) break } @@ -266,6 +267,9 @@ func (b *Sdk) PreUse(version Version, scope UseScope) (Version, error) { } } } + if newVersion == "" { + return version, nil + } return newVersion, nil }