From bf3739c823f6bd09a83a633f432a3c7191812ab9 Mon Sep 17 00:00:00 2001 From: Chance Date: Thu, 25 Jul 2024 09:47:45 +0800 Subject: [PATCH 1/2] fix: priority accurate matching version --- internal/sdk.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/internal/sdk.go b/internal/sdk.go index 6d32c086..3dd4a6e6 100644 --- a/internal/sdk.go +++ b/internal/sdk.go @@ -360,14 +360,16 @@ func (b *Sdk) PreUse(version Version, scope UseScope) (Version, error) { func (b *Sdk) Use(version Version, scope UseScope) error { logger.Debugf("Use SDK version: %s, scope:%v\n", string(version), scope) - version, err := b.PreUse(version, scope) - if err != nil { - return err - } - - label := b.label(version) if !b.CheckExists(version) { - return fmt.Errorf("%s is not installed", label) + v, err := b.PreUse(version, scope) + if err != nil { + return err + } + version = v + label := b.label(version) + if !b.CheckExists(version) { + return fmt.Errorf("%s is not installed", label) + } } if !env.IsHookEnv() { From 634247e8123e1a763e0984da3e2b093243ee833d Mon Sep 17 00:00:00 2001 From: Chance Date: Fri, 26 Jul 2024 11:24:19 +0800 Subject: [PATCH 2/2] Revert `PreUse` hook --- internal/sdk.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/internal/sdk.go b/internal/sdk.go index 3dd4a6e6..306b90f8 100644 --- a/internal/sdk.go +++ b/internal/sdk.go @@ -332,6 +332,10 @@ func (b *Sdk) PreUse(version Version, scope UseScope) (Version, error) { // not want to change the version or not implement the PreUse function. // We can simply fuzzy match the version based on the input version. if newVersion == "" { + // Before fuzzy matching, perform exact matching first. + if b.CheckExists(version) { + return version, nil + } installedVersions := make(util.VersionSort, 0, len(installedSdks)) for _, sdk := range installedSdks { installedVersions = append(installedVersions, string(sdk.Main.Version)) @@ -360,16 +364,14 @@ func (b *Sdk) PreUse(version Version, scope UseScope) (Version, error) { func (b *Sdk) Use(version Version, scope UseScope) error { logger.Debugf("Use SDK version: %s, scope:%v\n", string(version), scope) + version, err := b.PreUse(version, scope) + if err != nil { + return err + } + + label := b.label(version) if !b.CheckExists(version) { - v, err := b.PreUse(version, scope) - if err != nil { - return err - } - version = v - label := b.label(version) - if !b.CheckExists(version) { - return fmt.Errorf("%s is not installed", label) - } + return fmt.Errorf("%s is not installed", label) } if !env.IsHookEnv() {