From ab52cef72aab32ef6b8654d6f71c1b25f9a887e3 Mon Sep 17 00:00:00 2001 From: Marcel Schramm Date: Sat, 6 Apr 2024 21:03:28 +0200 Subject: [PATCH] Versions now allows limiting the version count --- cmd/spoon/versions.go | 8 ++++++-- pkg/scoop/scoop.go | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/cmd/spoon/versions.go b/cmd/spoon/versions.go index bee3a58..21ef625 100644 --- a/cmd/spoon/versions.go +++ b/cmd/spoon/versions.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "math" "github.com/Bios-Marcel/spoon/pkg/scoop" "github.com/spf13/cobra" @@ -24,10 +25,11 @@ func versionsCmd() *cobra.Command { } if app == nil { - return fmt.Errorf("app does not exist") + return fmt.Errorf("app '%s' does not exist", args[0]) } - versions, err := app.AvailableVersions() + count := must(cmd.Flags().GetInt("count")) + versions, err := app.AvailableVersionsN(count) if err != nil { return fmt.Errorf("error retrieving versions: %w", err) } @@ -39,5 +41,7 @@ func versionsCmd() *cobra.Command { }), } + cmd.Flags().IntP("count", "c", math.MaxInt32, "defines how many versions you want to fetch (impacts speed)") + return cmd } diff --git a/pkg/scoop/scoop.go b/pkg/scoop/scoop.go index fff5b99..6295e9b 100644 --- a/pkg/scoop/scoop.go +++ b/pkg/scoop/scoop.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "io" + "math" "os" "path/filepath" "regexp" @@ -793,6 +794,10 @@ func (scoop *Scoop) Install(apps []string, arch ArchitectureKey) error { var ErrBucketNoGitDir = errors.New(".git dir at path not found") func (a *App) AvailableVersions() ([]string, error) { + return a.AvailableVersionsN(math.MaxInt32) +} + +func (a *App) AvailableVersionsN(maxVersions int) ([]string, error) { repoPath, relManifestPath := git.GitPaths(a.ManifestPath()) if repoPath == "" || relManifestPath == "" { return nil, ErrBucketNoGitDir @@ -808,6 +813,9 @@ func (a *App) AvailableVersions() ([]string, error) { iter := jsoniter.ParseBytes(jsoniter.ConfigFastest, nil) var versions []string for result := range resultChan { + if len(versions) >= maxVersions { + break + } if result.Error != nil { return nil, result.Error }