Skip to content

Commit a592fe5

Browse files
authored
Indicate of a package version list in devbox search is truncated (#2044)
## Summary Current `devbox search` UI only shows the 10 newest versions for a package, unless the developer runs the command with `--show-all`. With the current presentation, this may confuse developers by making it seem like only 10 versions are available at all. This pr Adds a `...` at the end to indicate that more versions are available. For example: ``` Found 8+ results for "python": * python (3.13.0a6, 3.13.0a5, 3.13.0a3, 3.13.0a2, 3.13.0a1, 3.12.3, 3.12.2, 3.12.1, 3.12.0, 3.12.0rc3 ...) * python-cosmopolitan (3.6.14) * python-launcher (1.0.0) * python-qt (3.5.2, 3.5.1, 3.4.2, 3.3.0, 3.2) * python-swiftclient (4.2.0, 4.1.0, 4.0.0, 3.13.1, 3.13.0, 3.12.0) * python-language-server (2022-02-18, 2021-09-08, 2021-05-20, 2020-10-08, 2020-06-19, 2020-04-24) * python-matter-server (5.10.0, 5.9.0, 5.8.1, 5.8.0, 5.7.0b2, 5.5.3, 5.1.1, 5.0.3, 4.0.2, 4.0.1 ...) * python-full (3.13.0a6, 3.13.0a5, 3.13.0a3, 3.13.0a2, 3.13.0a1, 3.12.3, 3.12.2, 3.12.1, 3.12.0, 3.11.9 ...) Warning: Showing top 10 results and truncated versions. Use --show-all to show all. ``` ## How was it tested? Debugged locally, tested with `go` and `python` Also verified that the ellipses don't appear when the `--show-all` flag is set
1 parent ec0a703 commit a592fe5

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

internal/boxcli/search.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ import (
99
"math"
1010
"strings"
1111

12+
"github.com/samber/lo"
1213
"github.com/spf13/cobra"
1314

1415
"go.jetpack.io/devbox/internal/boxcli/usererr"
1516
"go.jetpack.io/devbox/internal/searcher"
1617
"go.jetpack.io/devbox/internal/ux"
1718
)
1819

20+
const trimmedVersionsLength = 10
21+
1922
type searchCmdFlags struct {
2023
showAll bool
2124
}
@@ -81,15 +84,15 @@ func printSearchResults(
8184

8285
resultsAreTrimmed := false
8386
pkgs := results.Packages
84-
if !showAll && len(pkgs) > 10 {
87+
if !showAll && len(pkgs) > trimmedVersionsLength {
8588
resultsAreTrimmed = true
8689
pkgs = results.Packages[:int(math.Min(10, float64(len(results.Packages))))]
8790
}
8891

8992
for _, pkg := range pkgs {
9093
nonEmptyVersions := []string{}
9194
for i, v := range pkg.Versions {
92-
if !showAll && i >= 10 {
95+
if !showAll && i >= trimmedVersionsLength {
9396
resultsAreTrimmed = true
9497
break
9598
}
@@ -100,7 +103,8 @@ func printSearchResults(
100103

101104
versionString := ""
102105
if len(nonEmptyVersions) > 0 {
103-
versionString = fmt.Sprintf(" (%s)", strings.Join(nonEmptyVersions, ", "))
106+
ellipses := lo.Ternary(resultsAreTrimmed && pkg.NumVersions > trimmedVersionsLength, " ...", "")
107+
versionString = fmt.Sprintf(" (%s%s)", strings.Join(nonEmptyVersions, ", "), ellipses)
104108
}
105109
fmt.Fprintf(w, "* %s %s\n", pkg.Name, versionString)
106110
}

0 commit comments

Comments
 (0)