Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pkg/cmd/connection_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type connectionListCmd struct {
disabled bool
limit int
output string
next string
prev string
}

func newConnectionListCmd() *connectionListCmd {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions pkg/cmd/destination_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type destinationListCmd struct {
disabled bool
limit int
output string
next string
prev string
}

func newDestinationListCmd() *destinationListCmd {
Expand All @@ -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
Expand All @@ -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 {
Expand Down
24 changes: 24 additions & 0 deletions pkg/cmd/gateway_list_pagination_test.go
Original file line number Diff line number Diff line change
@@ -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"))
})
}
}
10 changes: 10 additions & 0 deletions pkg/cmd/source_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type sourceListCmd struct {
disabled bool
limit int
output string
next string
prev string
}

func newSourceListCmd() *sourceListCmd {
Expand All @@ -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
Expand All @@ -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 {
Expand Down