diff --git a/pkg/controller/generate/controller.go b/pkg/controller/generate/controller.go index 140cd68cd..846b23263 100644 --- a/pkg/controller/generate/controller.go +++ b/pkg/controller/generate/controller.go @@ -29,7 +29,7 @@ type Controller struct { } type FuzzyGetter interface { - Get(ctx context.Context, logE *logrus.Entry, pkg *registry.PackageInfo, useFinder bool) string + Get(ctx context.Context, logE *logrus.Entry, pkg *registry.PackageInfo, currentVersion string, useFinder bool) string } type FuzzyFinder interface { diff --git a/pkg/controller/generate/generate.go b/pkg/controller/generate/generate.go index f4dc1193c..969f99fde 100644 --- a/pkg/controller/generate/generate.go +++ b/pkg/controller/generate/generate.go @@ -197,7 +197,7 @@ func (c *Controller) getOutputtedPkg(ctx context.Context, logE *logrus.Entry, pa outputPkg.Registry = "" } if outputPkg.Version == "" { - version := c.fuzzyGetter.Get(ctx, logE, pkg.PackageInfo, param.SelectVersion) + version := c.fuzzyGetter.Get(ctx, logE, pkg.PackageInfo, "", param.SelectVersion) if version == "" { outputPkg.Version = "[SET PACKAGE VERSION]" return outputPkg diff --git a/pkg/controller/update/controller.go b/pkg/controller/update/controller.go index e37fcdee7..a635a48a7 100644 --- a/pkg/controller/update/controller.go +++ b/pkg/controller/update/controller.go @@ -40,7 +40,7 @@ type ConfigReader interface { } type FuzzyGetter interface { - Get(ctx context.Context, logE *logrus.Entry, pkg *registry.PackageInfo, useFinder bool) string + Get(ctx context.Context, logE *logrus.Entry, pkg *registry.PackageInfo, currentVersion string, useFinder bool) string } type RepositoriesService interface { diff --git a/pkg/controller/update/package.go b/pkg/controller/update/package.go index 65c8dd808..218b3153d 100644 --- a/pkg/controller/update/package.go +++ b/pkg/controller/update/package.go @@ -79,7 +79,7 @@ func (c *Controller) getPackageNewVersion(ctx context.Context, logE *logrus.Entr return "" } } - return c.fuzzyGetter.Get(ctx, logE, pkg.PackageInfo, param.SelectVersion) + return c.fuzzyGetter.Get(ctx, logE, pkg.PackageInfo, pkg.Package.Version, param.SelectVersion) } func (c *Controller) selectPackages(logE *logrus.Entry, cfgFilePath string) (map[string]struct{}, error) { diff --git a/pkg/versiongetter/get.go b/pkg/versiongetter/get.go index 9034daebb..9f2ec587f 100644 --- a/pkg/versiongetter/get.go +++ b/pkg/versiongetter/get.go @@ -2,6 +2,7 @@ package versiongetter import ( "context" + "strings" "github.com/aquaproj/aqua/v2/pkg/config/registry" "github.com/aquaproj/aqua/v2/pkg/fuzzyfinder" @@ -30,7 +31,7 @@ func NewMockFuzzyGetter(s string) *MockFuzzyGetter { } } -func (g *MockFuzzyGetter) Get(ctx context.Context, _ *logrus.Entry, pkg *registry.PackageInfo, useFinder bool) string { +func (g *MockFuzzyGetter) Get(ctx context.Context, _ *logrus.Entry, pkg *registry.PackageInfo, currentVersion string, useFinder bool) string { return g.s } @@ -39,7 +40,7 @@ type FuzzyFinder interface { FindMulti(items []*fuzzyfinder.Item, hasPreview bool) ([]int, error) } -func (g *FuzzyGetter) Get(ctx context.Context, _ *logrus.Entry, pkg *registry.PackageInfo, useFinder bool) string { +func (g *FuzzyGetter) Get(ctx context.Context, _ *logrus.Entry, pkg *registry.PackageInfo, currentVersion string, useFinder bool) string { //nolint:cyclop filters, err := createFilters(pkg) if err != nil { return "" @@ -50,15 +51,28 @@ func (g *FuzzyGetter) Get(ctx context.Context, _ *logrus.Entry, pkg *registry.Pa return "" } - if useFinder { + if useFinder { //nolint:nestif versions, err := versionGetter.List(ctx, pkg, filters) if err != nil { return "" } + currentVersionIndex := 0 + if currentVersion != "" { + for i, version := range versions { + if version.Item == currentVersion { + version.Item += " (*)" + currentVersionIndex = i + break + } + } + } idx, err := g.fuzzyFinder.Find(versions, true) if err != nil { return "" } + if idx == currentVersionIndex { + return strings.TrimSuffix(versions[idx].Item, " (*)") + } return versions[idx].Item }