Skip to content

Commit e22ecda

Browse files
authored
Merge pull request #218 from hookdeck/fix/pagination-cursor-display
fix: display pagination cursors in all list commands
2 parents 68be57b + 94dea65 commit e22ecda

18 files changed

Lines changed: 343 additions & 95 deletions

.github/workflows/test-acceptance.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ jobs:
2121
go-version: "1.24.9"
2222

2323
- name: Run Go Acceptance Tests
24-
run: go test ./test/acceptance/... -v -timeout 10m
24+
run: go test ./test/acceptance/... -v -timeout 20m

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ test-scripts/.install-test/
2020

2121
# Temporary OpenAPI spec download (large; do not commit)
2222
.plans/openapi-2025-07-01.json
23+
24+
# Claude Code temporary worktrees
25+
.claude/worktrees/

pkg/cmd/attempt_list.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cmd
22

33
import (
44
"context"
5-
"encoding/json"
65
"fmt"
76
"os"
87
"strconv"
@@ -81,11 +80,7 @@ func (ac *attemptListCmd) runAttemptListCmd(cmd *cobra.Command, args []string) e
8180
}
8281

8382
if ac.output == "json" {
84-
if len(resp.Models) == 0 {
85-
fmt.Println("[]")
86-
return nil
87-
}
88-
jsonBytes, err := json.MarshalIndent(resp.Models, "", " ")
83+
jsonBytes, err := marshalListResponseWithPagination(resp.Models, resp.Pagination)
8984
if err != nil {
9085
return fmt.Errorf("failed to marshal attempts to json: %w", err)
9186
}
@@ -106,5 +101,10 @@ func (ac *attemptListCmd) runAttemptListCmd(cmd *cobra.Command, args []string) e
106101
}
107102
fmt.Printf("%s #%d%s %s\n", color.Green(a.ID), a.AttemptNumber, status, a.Status)
108103
}
104+
105+
// Display pagination info
106+
commandExample := "hookdeck gateway attempt list"
107+
printPaginationInfo(resp.Pagination, commandExample)
108+
109109
return nil
110110
}

pkg/cmd/connection_list.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cmd
22

33
import (
44
"context"
5-
"encoding/json"
65
"fmt"
76
"os"
87
"strconv"
@@ -113,12 +112,7 @@ func (cc *connectionListCmd) runConnectionListCmd(cmd *cobra.Command, args []str
113112
}
114113

115114
if cc.output == "json" {
116-
if len(response.Models) == 0 {
117-
// Print an empty JSON array
118-
fmt.Println("[]")
119-
return nil
120-
}
121-
jsonBytes, err := json.MarshalIndent(response.Models, "", " ")
115+
jsonBytes, err := marshalListResponseWithPagination(response.Models, response.Pagination)
122116
if err != nil {
123117
return fmt.Errorf("failed to marshal connections to json: %w", err)
124118
}
@@ -175,5 +169,9 @@ func (cc *connectionListCmd) runConnectionListCmd(cmd *cobra.Command, args []str
175169
fmt.Println()
176170
}
177171

172+
// Display pagination info
173+
commandExample := "hookdeck gateway connection list"
174+
printPaginationInfo(response.Pagination, commandExample)
175+
178176
return nil
179177
}

pkg/cmd/destination_list.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cmd
22

33
import (
44
"context"
5-
"encoding/json"
65
"fmt"
76
"os"
87
"strconv"
@@ -77,11 +76,7 @@ func (dc *destinationListCmd) runDestinationListCmd(cmd *cobra.Command, args []s
7776
}
7877

7978
if dc.output == "json" {
80-
if len(resp.Models) == 0 {
81-
fmt.Println("[]")
82-
return nil
83-
}
84-
jsonBytes, err := json.MarshalIndent(resp.Models, "", " ")
79+
jsonBytes, err := marshalListResponseWithPagination(resp.Models, resp.Pagination)
8580
if err != nil {
8681
return fmt.Errorf("failed to marshal destinations to json: %w", err)
8782
}
@@ -111,5 +106,9 @@ func (dc *destinationListCmd) runDestinationListCmd(cmd *cobra.Command, args []s
111106
fmt.Println()
112107
}
113108

109+
// Display pagination info
110+
commandExample := "hookdeck gateway destination list"
111+
printPaginationInfo(resp.Pagination, commandExample)
112+
114113
return nil
115114
}

pkg/cmd/event_list.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cmd
22

33
import (
44
"context"
5-
"encoding/json"
65
"fmt"
76
"os"
87
"strconv"
@@ -177,11 +176,7 @@ func (ec *eventListCmd) runEventListCmd(cmd *cobra.Command, args []string) error
177176
}
178177

179178
if ec.output == "json" {
180-
if len(resp.Models) == 0 {
181-
fmt.Println("[]")
182-
return nil
183-
}
184-
jsonBytes, err := json.MarshalIndent(resp.Models, "", " ")
179+
jsonBytes, err := marshalListResponseWithPagination(resp.Models, resp.Pagination)
185180
if err != nil {
186181
return fmt.Errorf("failed to marshal events to json: %w", err)
187182
}
@@ -198,5 +193,10 @@ func (ec *eventListCmd) runEventListCmd(cmd *cobra.Command, args []string) error
198193
for _, e := range resp.Models {
199194
fmt.Printf("%s Status: %s Connection: %s\n", color.Green(e.ID), e.Status, e.WebhookID)
200195
}
196+
197+
// Display pagination info
198+
commandExample := "hookdeck gateway event list"
199+
printPaginationInfo(resp.Pagination, commandExample)
200+
201201
return nil
202202
}

pkg/cmd/pagination_output.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package cmd
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
7+
"github.com/hookdeck/hookdeck-cli/pkg/hookdeck"
8+
)
9+
10+
// printPaginationInfo displays pagination cursors for text output
11+
func printPaginationInfo(pagination hookdeck.PaginationResponse, commandExample string) {
12+
if pagination.Next == nil && pagination.Prev == nil {
13+
return
14+
}
15+
16+
fmt.Println()
17+
fmt.Println("Pagination:")
18+
if pagination.Prev != nil {
19+
fmt.Printf(" Prev: %s\n", *pagination.Prev)
20+
}
21+
if pagination.Next != nil {
22+
fmt.Printf(" Next: %s\n", *pagination.Next)
23+
}
24+
25+
if pagination.Next != nil {
26+
fmt.Println()
27+
fmt.Println("To get the next page:")
28+
fmt.Printf(" %s --next %s\n", commandExample, *pagination.Next)
29+
}
30+
}
31+
32+
// marshalListResponseWithPagination marshals a list response including pagination
33+
func marshalListResponseWithPagination(models interface{}, pagination hookdeck.PaginationResponse) ([]byte, error) {
34+
response := map[string]interface{}{
35+
"models": models,
36+
"pagination": pagination,
37+
}
38+
return json.MarshalIndent(response, "", " ")
39+
}

pkg/cmd/request_list.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cmd
22

33
import (
44
"context"
5-
"encoding/json"
65
"fmt"
76
"os"
87
"strconv"
@@ -141,11 +140,7 @@ func (rc *requestListCmd) runRequestListCmd(cmd *cobra.Command, args []string) e
141140
}
142141

143142
if rc.output == "json" {
144-
if len(resp.Models) == 0 {
145-
fmt.Println("[]")
146-
return nil
147-
}
148-
jsonBytes, err := json.MarshalIndent(resp.Models, "", " ")
143+
jsonBytes, err := marshalListResponseWithPagination(resp.Models, resp.Pagination)
149144
if err != nil {
150145
return fmt.Errorf("failed to marshal requests to json: %w", err)
151146
}
@@ -162,5 +157,10 @@ func (rc *requestListCmd) runRequestListCmd(cmd *cobra.Command, args []string) e
162157
for _, r := range resp.Models {
163158
fmt.Printf("%s %s (events: %d)\n", color.Green(r.ID), r.SourceID, r.EventsCount)
164159
}
160+
161+
// Display pagination info
162+
commandExample := "hookdeck gateway request list"
163+
printPaginationInfo(resp.Pagination, commandExample)
164+
165165
return nil
166166
}

pkg/cmd/source_list.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cmd
22

33
import (
44
"context"
5-
"encoding/json"
65
"fmt"
76
"os"
87
"strconv"
@@ -77,11 +76,7 @@ func (sc *sourceListCmd) runSourceListCmd(cmd *cobra.Command, args []string) err
7776
}
7877

7978
if sc.output == "json" {
80-
if len(resp.Models) == 0 {
81-
fmt.Println("[]")
82-
return nil
83-
}
84-
jsonBytes, err := json.MarshalIndent(resp.Models, "", " ")
79+
jsonBytes, err := marshalListResponseWithPagination(resp.Models, resp.Pagination)
8580
if err != nil {
8681
return fmt.Errorf("failed to marshal sources to json: %w", err)
8782
}
@@ -109,5 +104,9 @@ func (sc *sourceListCmd) runSourceListCmd(cmd *cobra.Command, args []string) err
109104
fmt.Println()
110105
}
111106

107+
// Display pagination info
108+
commandExample := "hookdeck gateway source list"
109+
printPaginationInfo(resp.Pagination, commandExample)
110+
112111
return nil
113112
}

pkg/cmd/transformation_executions.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,7 @@ func (tc *transformationExecutionsListCmd) run(cmd *cobra.Command, args []string
112112
}
113113

114114
if tc.output == "json" {
115-
if len(resp.Models) == 0 {
116-
fmt.Println("[]")
117-
return nil
118-
}
119-
jsonBytes, err := json.MarshalIndent(resp.Models, "", " ")
115+
jsonBytes, err := marshalListResponseWithPagination(resp.Models, resp.Pagination)
120116
if err != nil {
121117
return fmt.Errorf("failed to marshal executions to json: %w", err)
122118
}
@@ -133,6 +129,11 @@ func (tc *transformationExecutionsListCmd) run(cmd *cobra.Command, args []string
133129
for _, e := range resp.Models {
134130
fmt.Printf("%s %s\n", color.Green(e.ID), e.CreatedAt.Format("2006-01-02 15:04:05"))
135131
}
132+
133+
// Display pagination info
134+
commandExample := "hookdeck gateway transformation executions list"
135+
printPaginationInfo(resp.Pagination, commandExample)
136+
136137
return nil
137138
}
138139

0 commit comments

Comments
 (0)