Skip to content

Commit 401af7b

Browse files
milos-lkclaude
andauthored
Add pagination support to ingress list (#915)
* Add pagination support to ingress list Mirror the egress list pagination: a new --limit flag walks pages via NextPageToken, prepending each older page so output stays in chronological oldest-first order. Without --limit, behavior is unchanged (single API page). JSON output keeps the response-object shape for compatibility. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Regenerate fish autocomplete for ingress list --limit Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent a60d4f7 commit 401af7b

3 files changed

Lines changed: 412 additions & 8 deletions

File tree

autocomplete/fish_autocomplete

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ complete -x -c lk -n '__fish_seen_subcommand_from ingress; and __fish_seen_subco
619619
complete -x -c lk -n '__fish_seen_subcommand_from ingress; and not __fish_seen_subcommand_from create update list delete help h' -a 'list' -d 'List all active ingress'
620620
complete -c lk -n '__fish_seen_subcommand_from ingress; and __fish_seen_subcommand_from list' -f -l room -r -d 'Limits list to a certain room `NAME`'
621621
complete -c lk -n '__fish_seen_subcommand_from ingress; and __fish_seen_subcommand_from list' -f -l id -r -d 'List a specific ingress `ID`'
622+
complete -c lk -n '__fish_seen_subcommand_from ingress; and __fish_seen_subcommand_from list' -f -l limit -r -d 'maximum number of items to return. If unset, defaults to API page size'
622623
complete -c lk -n '__fish_seen_subcommand_from ingress; and __fish_seen_subcommand_from list' -f -l json -s j -d 'Output as JSON'
623624
complete -c lk -n '__fish_seen_subcommand_from ingress; and __fish_seen_subcommand_from list' -f -l help -s h -d 'show help'
624625
complete -x -c lk -n '__fish_seen_subcommand_from ingress; and __fish_seen_subcommand_from list; and not __fish_seen_subcommand_from help h' -a 'help' -d 'Shows a list of commands or help for one command'

cmd/lk/ingress.go

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ var (
7979
Usage: "List a specific ingress `ID`",
8080
Required: false,
8181
},
82+
&cli.IntFlag{
83+
Name: "limit",
84+
Usage: "maximum number of items to return. If unset, defaults to API page size",
85+
},
8286
jsonFlag,
8387
},
8488
},
@@ -209,23 +213,53 @@ func updateIngress(ctx context.Context, cmd *cli.Command) error {
209213
}
210214

211215
func listIngress(ctx context.Context, cmd *cli.Command) error {
212-
res, err := ingressClient.ListIngress(context.Background(), &livekit.ListIngressRequest{
213-
RoomName: cmd.String("room"),
214-
IngressId: cmd.String("id"),
215-
})
216-
if err != nil {
217-
return err
216+
var items []*livekit.IngressInfo
217+
if cmd.IsSet("id") {
218+
res, err := ingressClient.ListIngress(ctx, &livekit.ListIngressRequest{
219+
RoomName: cmd.String("room"),
220+
IngressId: cmd.String("id"),
221+
})
222+
if err != nil {
223+
return err
224+
}
225+
items = res.Items
226+
} else {
227+
limit := cmd.Int("limit")
228+
var err error
229+
var res *livekit.ListIngressResponse
230+
for res == nil || (len(items) < limit && res.NextPageToken.GetToken() != "") {
231+
req := &livekit.ListIngressRequest{
232+
RoomName: cmd.String("room"),
233+
}
234+
235+
if res != nil {
236+
req.PageToken = &livekit.TokenPagination{Token: res.NextPageToken.GetToken()}
237+
}
238+
239+
res, err = ingressClient.ListIngress(ctx, req)
240+
if err != nil {
241+
return err
242+
}
243+
244+
resItems := res.Items
245+
if remaining := limit - len(items); limit > 0 && len(resItems) > remaining {
246+
resItems = resItems[len(resItems)-remaining:]
247+
}
248+
249+
// each page has older items than the previous one, but ordering within each page is newest last
250+
items = append(resItems, items...)
251+
}
218252
}
219253

220254
// NOTE: previously, the `verbose` flag was used to output JSON in addition to the table.
221255
// This is inconsistent with other commands in which verbose is used for debug info, but is
222256
// kept for compatibility with the previous behavior.
223257
if cmd.Bool("verbose") || cmd.Bool("json") {
224-
util.PrintJSON(res)
258+
return util.PrintJSONTo(cmd.Root().Writer, &livekit.ListIngressResponse{Items: items})
225259
} else {
226260
table := util.CreateTable().
227261
Headers("IngressID", "Name", "Room", "StreamKey", "URL", "Status", "Error")
228-
for _, item := range res.Items {
262+
for _, item := range items {
229263
if item == nil {
230264
continue
231265
}

0 commit comments

Comments
 (0)