Skip to content

Commit f27a711

Browse files
add auto pagination
1 parent 7e48660 commit f27a711

1 file changed

Lines changed: 31 additions & 6 deletions

File tree

  • pkg/commands/apisecurity/tags

pkg/commands/apisecurity/tags/list.go

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,46 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error {
7171
if !ok {
7272
return errors.New("failed to convert interface to a fastly client")
7373
}
74+
// Auto-paginate through all results
75+
var allTags []operations.OperationTag
76+
page := 0
77+
limit := 100
7478

7579
input := &operations.ListTagsInput{
7680
ServiceID: &serviceID,
7781
}
7882

79-
tags, err := operations.ListTags(context.TODO(), fc, input)
80-
if err != nil {
81-
c.Globals.ErrLog.Add(err)
82-
return err
83+
for {
84+
input.Page = &page
85+
input.Limit = &limit
86+
87+
tags, err := operations.ListTags(context.TODO(), fc, input)
88+
if err != nil {
89+
c.Globals.ErrLog.AddWithContext(err, map[string]any{
90+
"Service ID": serviceID,
91+
"Page": page,
92+
})
93+
return err
94+
}
95+
96+
if tags == nil || len(tags.Data) == 0 {
97+
break
98+
}
99+
100+
allTags = append(allTags, tags.Data...)
101+
102+
// Check if we've fetched all results
103+
if len(allTags) >= tags.Meta.Total {
104+
break
105+
}
106+
107+
page++
83108
}
84109

85-
if ok, err := c.WriteJSON(out, tags); ok {
110+
if ok, err := c.WriteJSON(out, allTags); ok {
86111
return err
87112
}
88113

89-
text.PrintOperationTagsTbl(out, tags.Data)
114+
text.PrintOperationTagsTbl(out, allTags)
90115
return nil
91116
}

0 commit comments

Comments
 (0)