Skip to content

Commit 16566c5

Browse files
fix: fix for off-by-one error in pagination logic
1 parent 180bf35 commit 16566c5

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
@@ -378,6 +378,7 @@ type HasRawJSON interface {
378378

379379
// For an iterator over different value types, display its values to the user in
380380
// different formats.
381+
// -1 is used to signal no limit of items to display
381382
func ShowJSONIterator[T any](stdout *os.File, title string, iter jsonview.Iterator[T], format string, transform string, itemsToDisplay int64) error {
382383
if format == "explore" {
383384
return jsonview.ExploreJSONStream(title, iter)
@@ -393,10 +394,8 @@ func ShowJSONIterator[T any](stdout *os.File, title string, iter jsonview.Iterat
393394
usePager := false
394395
output := []byte{}
395396
numberOfNewlines := 0
396-
for iter.Next() {
397-
if itemsToDisplay == 0 {
398-
break
399-
}
397+
// -1 is used to signal no limit of items to display
398+
for itemsToDisplay != 0 && iter.Next() {
400399
item := iter.Current()
401400
var obj gjson.Result
402401
if hasRaw, ok := any(item).(HasRawJSON); ok {

0 commit comments

Comments
 (0)