Skip to content

Commit 2eec67c

Browse files
fix: fix for off-by-one error in pagination logic
1 parent a9a88ea commit 2eec67c

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

pkg/cmd/cmdutil.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ type HasRawJSON interface {
384384

385385
// For an iterator over different value types, display its values to the user in
386386
// different formats.
387+
// -1 is used to signal no limit of items to display
387388
func ShowJSONIterator[T any](stdout *os.File, title string, iter jsonview.Iterator[T], format string, transform string, itemsToDisplay int64) error {
388389
if format == "explore" {
389390
return jsonview.ExploreJSONStream(title, iter)
@@ -399,10 +400,8 @@ func ShowJSONIterator[T any](stdout *os.File, title string, iter jsonview.Iterat
399400
usePager := false
400401
output := []byte{}
401402
numberOfNewlines := 0
402-
for iter.Next() {
403-
if itemsToDisplay == 0 {
404-
break
405-
}
403+
// -1 is used to signal no limit of items to display
404+
for itemsToDisplay != 0 && iter.Next() {
406405
item := iter.Current()
407406
var obj gjson.Result
408407
if hasRaw, ok := any(item).(HasRawJSON); ok {

0 commit comments

Comments
 (0)