@@ -26,12 +26,10 @@ type ListCommand struct {
2626 serviceName argparser.OptionalServiceNameID
2727
2828 // Optional.
29- domain argparser.OptionalString
30- method argparser.OptionalString
31- path argparser.OptionalString
32- tagID argparser.OptionalString
33- page argparser.OptionalInt
34- perPage argparser.OptionalInt
29+ domain argparser.OptionalString
30+ method argparser.OptionalString
31+ path argparser.OptionalString
32+ tagID argparser.OptionalString
3533}
3634
3735// NewListCommand returns a usable command registered under the parent.
@@ -63,8 +61,6 @@ func NewListCommand(parent argparser.Registerer, g *global.Data) *ListCommand {
6361 c .CmdClause .Flag ("method" , "Filters operations by HTTP method (e.g., GET, POST, PUT)" ).Action (c .method .Set ).StringVar (& c .method .Value )
6462 c .CmdClause .Flag ("path" , "Filters operations by path (exact match)" ).Action (c .path .Set ).StringVar (& c .path .Value )
6563 c .CmdClause .Flag ("tag-id" , "Filters operations by tag ID" ).Action (c .tagID .Set ).StringVar (& c .tagID .Value )
66- c .CmdClause .Flag ("page" , "Page number for pagination (0-indexed)" ).Action (c .page .Set ).IntVar (& c .page .Value )
67- c .CmdClause .Flag ("per-page" , "Number of items per page (default: 100)" ).Action (c .perPage .Set ).IntVar (& c .perPage .Value )
6864 c .RegisterFlagBool (c .JSONFlag ()) // --json
6965
7066 return & c
@@ -99,49 +95,56 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error {
9995 c .input .TagID = & c .tagID .Value
10096 }
10197
102- // Set pagination parameters
103- if c .page .WasSet {
104- c .input .Page = & c .page .Value
105- }
106-
107- if c .perPage .WasSet {
108- c .input .Limit = & c .perPage .Value
109- }
110-
11198 fc , ok := c .Globals .APIClient .(* fastly.Client )
11299 if ! ok {
113100 return errors .New ("failed to convert interface to a fastly client" )
114101 }
115102
116- o , err := operations .ListOperations (context .TODO (), fc , & c .input )
117- if err != nil {
118- c .Globals .ErrLog .AddWithContext (err , map [string ]any {
119- "Service ID" : serviceID ,
120- "Domain" : c .domain .Value ,
121- "Method" : c .method .Value ,
122- "Path" : c .path .Value ,
123- "Tag ID" : c .tagID .Value ,
124- "Page" : c .page .Value ,
125- "Per Page" : c .perPage .Value ,
126- })
127- return err
128- }
103+ // Auto-paginate through all results
104+ var allOperations []operations.Operation
105+ page := 0
106+ limit := 100
107+
108+ for {
109+ c .input .Page = & page
110+ c .input .Limit = & limit
111+
112+ o , err := operations .ListOperations (context .TODO (), fc , & c .input )
113+ if err != nil {
114+ c .Globals .ErrLog .AddWithContext (err , map [string ]any {
115+ "Service ID" : serviceID ,
116+ "Domain" : c .domain .Value ,
117+ "Method" : c .method .Value ,
118+ "Path" : c .path .Value ,
119+ "Tag ID" : c .tagID .Value ,
120+ "Page" : page ,
121+ })
122+ return err
123+ }
124+
125+ if o == nil || len (o .Data ) == 0 {
126+ break
127+ }
128+
129+ allOperations = append (allOperations , o .Data ... )
129130
130- if o == nil {
131- o = & operations. Operations {
132- Data : []operations. Operation {},
131+ // Check if we've fetched all results
132+ if len ( allOperations ) >= o . Meta . Total {
133+ break
133134 }
135+
136+ page ++
134137 }
135138
136- if ok , err := c .WriteJSON (out , o . Data ); ok {
139+ if ok , err := c .WriteJSON (out , allOperations ); ok {
137140 return err
138141 }
139142
140143 if ! c .Globals .Verbose () {
141- return c .printSummary (out , o . Data )
144+ return c .printSummary (out , allOperations )
142145 }
143146
144- return c .printVerbose (out , o . Data )
147+ return c .printVerbose (out , allOperations )
145148}
146149
147150// printSummary displays the operations in a table format.
0 commit comments