diff --git a/pkg/cmd/connection_list.go b/pkg/cmd/connection_list.go index 144c556e..883c61d7 100644 --- a/pkg/cmd/connection_list.go +++ b/pkg/cmd/connection_list.go @@ -21,6 +21,8 @@ type connectionListCmd struct { disabled bool limit int output string + next string + prev string } func newConnectionListCmd() *connectionListCmd { @@ -58,6 +60,8 @@ Examples: cc.cmd.Flags().StringVar(&cc.destinationID, "destination-id", "", "Filter by destination ID") cc.cmd.Flags().BoolVar(&cc.disabled, "disabled", false, "Include disabled connections") cc.cmd.Flags().IntVar(&cc.limit, "limit", 100, "Limit number of results") + cc.cmd.Flags().StringVar(&cc.next, "next", "", "Pagination cursor for next page") + cc.cmd.Flags().StringVar(&cc.prev, "prev", "", "Pagination cursor for previous page") cc.cmd.Flags().Var(newOutputFormatValue(&cc.output), "output", "Output format (json)") return cc @@ -104,6 +108,12 @@ func (cc *connectionListCmd) runConnectionListCmd(cmd *cobra.Command, args []str } params["limit"] = strconv.Itoa(cc.limit) + if cc.next != "" { + params["next"] = cc.next + } + if cc.prev != "" { + params["prev"] = cc.prev + } // List connections response, err := client.ListConnections(context.Background(), params) diff --git a/pkg/cmd/destination_list.go b/pkg/cmd/destination_list.go index 3dd1e008..1e36e821 100644 --- a/pkg/cmd/destination_list.go +++ b/pkg/cmd/destination_list.go @@ -20,6 +20,8 @@ type destinationListCmd struct { disabled bool limit int output string + next string + prev string } func newDestinationListCmd() *destinationListCmd { @@ -44,6 +46,8 @@ Examples: dc.cmd.Flags().StringVar(&dc.destType, "type", "", "Filter by destination type (HTTP, CLI, MOCK_API)") dc.cmd.Flags().BoolVar(&dc.disabled, "disabled", false, "Include disabled destinations") dc.cmd.Flags().IntVar(&dc.limit, "limit", 100, "Limit number of results") + dc.cmd.Flags().StringVar(&dc.next, "next", "", "Pagination cursor for next page") + dc.cmd.Flags().StringVar(&dc.prev, "prev", "", "Pagination cursor for previous page") dc.cmd.Flags().Var(newOutputFormatValue(&dc.output), "output", "Output format (json)") return dc @@ -69,6 +73,12 @@ func (dc *destinationListCmd) runDestinationListCmd(cmd *cobra.Command, args []s params["disabled"] = "false" } params["limit"] = strconv.Itoa(dc.limit) + if dc.next != "" { + params["next"] = dc.next + } + if dc.prev != "" { + params["prev"] = dc.prev + } resp, err := client.ListDestinations(context.Background(), params) if err != nil { diff --git a/pkg/cmd/gateway_list_pagination_test.go b/pkg/cmd/gateway_list_pagination_test.go new file mode 100644 index 00000000..eda6652d --- /dev/null +++ b/pkg/cmd/gateway_list_pagination_test.go @@ -0,0 +1,24 @@ +package cmd + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +// The text output of these list commands tells the user to pass --next to get +// the next page, so each of them must accept --next/--prev and forward the +// cursor to the API. +func TestResourceListSendsPaginationCursors(t *testing.T) { + for _, resource := range []string{"source", "destination", "connection"} { + t.Run(resource, func(t *testing.T) { + query := captureListQuery(t, + "gateway", resource, "list", + "--next", "cursor_next", + "--prev", "cursor_prev", + ) + assert.Equal(t, "cursor_next", query.Get("next")) + assert.Equal(t, "cursor_prev", query.Get("prev")) + }) + } +} diff --git a/pkg/cmd/source_list.go b/pkg/cmd/source_list.go index a5af75ca..d63e1603 100644 --- a/pkg/cmd/source_list.go +++ b/pkg/cmd/source_list.go @@ -20,6 +20,8 @@ type sourceListCmd struct { disabled bool limit int output string + next string + prev string } func newSourceListCmd() *sourceListCmd { @@ -44,6 +46,8 @@ Examples: sc.cmd.Flags().StringVar(&sc.sourceType, "type", "", "Filter by source type (e.g. WEBHOOK, STRIPE)") sc.cmd.Flags().BoolVar(&sc.disabled, "disabled", false, "Include disabled sources") sc.cmd.Flags().IntVar(&sc.limit, "limit", 100, "Limit number of results") + sc.cmd.Flags().StringVar(&sc.next, "next", "", "Pagination cursor for next page") + sc.cmd.Flags().StringVar(&sc.prev, "prev", "", "Pagination cursor for previous page") sc.cmd.Flags().Var(newOutputFormatValue(&sc.output), "output", "Output format (json)") return sc @@ -69,6 +73,12 @@ func (sc *sourceListCmd) runSourceListCmd(cmd *cobra.Command, args []string) err params["disabled"] = "false" } params["limit"] = strconv.Itoa(sc.limit) + if sc.next != "" { + params["next"] = sc.next + } + if sc.prev != "" { + params["prev"] = sc.prev + } resp, err := client.ListSources(context.Background(), params) if err != nil {