Skip to content

Commit

Permalink
Versions now allows limiting the version count
Browse files Browse the repository at this point in the history
  • Loading branch information
Bios-Marcel committed Apr 6, 2024
1 parent 3033010 commit ab52cef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cmd/spoon/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"math"

"github.com/Bios-Marcel/spoon/pkg/scoop"
"github.com/spf13/cobra"
Expand All @@ -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)
}
Expand All @@ -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
}
8 changes: 8 additions & 0 deletions pkg/scoop/scoop.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"io"
"math"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit ab52cef

Please sign in to comment.