Skip to content

Commit

Permalink
Merge pull request #115 from cgascoig/pagination_103
Browse files Browse the repository at this point in the history
Add support for auto pagination
  • Loading branch information
cgascoig authored Aug 11, 2023
2 parents 845cc19 + 46d7857 commit c71e5ae
Show file tree
Hide file tree
Showing 5 changed files with 53,401 additions and 5,810 deletions.
12 changes: 11 additions & 1 deletion generator/cli.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,15 @@ func () *cobra.Command {
{{ end }}
{{ end }}

res, err = operation.Execute(client, args, queryParams)
if autoPaginate, err2 := cmd.Flags().GetBool("auto-paginate"); err2 == nil && autoPaginate {
var batchSize = 100
if _batchSize, err3 := cmd.Flags().GetInt("auto-paginate-batch-size"); err3 == nil {
batchSize = _batchSize
}
res, err = ExecuteWithPagination(&operation, batchSize, client, args, queryParams)
} else {
res, err = operation.Execute(client, args, queryParams)
}
resultHandler(res, err, util.ResultOpt{SingleResult: &singleResult})
},
{{ end }}
Expand Down Expand Up @@ -143,6 +151,8 @@ Provide resource body as JSON on standard input{{ end }}`,
cmd.Flags().String("top", "", "Maximum number of results to return. Use with --skip for pagination of results")
cmd.Flags().String("skip", "", "Number of objects to skip and not include in results. Use with --top for pagination of results")
cmd.Flags().String("name", "", "Filter by exact name (note: if both --filter and --name are supplied, --name takes precedence")
cmd.Flags().Bool("auto-paginate", false, "Automatically execute batch requests to retrieve all results")
cmd.Flags().Int("auto-paginate-batch-size", 100, "Number of results to request per batch when using auto-paginate")
{{ end }}
{{ end }}
{{ end }}
Expand Down
Loading

0 comments on commit c71e5ae

Please sign in to comment.