@@ -12,14 +12,20 @@ import (
1212 "github.com/stackitcloud/stackit-cli/internal/pkg/args"
1313 cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors"
1414 "github.com/stackitcloud/stackit-cli/internal/pkg/examples"
15+ "github.com/stackitcloud/stackit-cli/internal/pkg/flags"
1516 "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1617 "github.com/stackitcloud/stackit-cli/internal/pkg/print"
1718 "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/client"
1819 "github.com/stackitcloud/stackit-cli/internal/pkg/tables"
1920)
2021
22+ const (
23+ limitFlag = "limit"
24+ )
25+
2126type inputModel struct {
2227 * globalflags.GlobalFlagModel
28+ Limit * int64
2329}
2430
2531func NewCmd (params * types.CmdParams ) * cobra.Command {
@@ -55,25 +61,49 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
5561 return outputResult (params .Printer , model .OutputFormat , flavors .Flavors )
5662 },
5763 }
64+
65+ configureFlags (cmd )
5866 return cmd
5967}
6068
69+ func configureFlags (cmd * cobra.Command ) {
70+ cmd .Flags ().Int64 (limitFlag , 0 , "Maximum number of entries to list" )
71+ }
72+
6173func parseInput (p * print.Printer , cmd * cobra.Command , _ []string ) (* inputModel , error ) {
6274 globalFlags := globalflags .Parse (p , cmd )
6375 if globalFlags .ProjectId == "" {
6476 return nil , & cliErr.ProjectIdError {}
6577 }
6678
79+ limit := flags .FlagToInt64Pointer (p , cmd , limitFlag )
80+ if limit != nil && * limit < 1 {
81+ return nil , & cliErr.FlagValidationError {
82+ Flag : limitFlag ,
83+ Details : "must be greater than 0" ,
84+ }
85+ }
86+
6787 model := inputModel {
6888 GlobalFlagModel : globalFlags ,
89+ Limit : limit ,
6990 }
7091
7192 p .DebugInputModel (model )
7293 return & model , nil
7394}
7495
7596func buildRequest (ctx context.Context , model * inputModel , apiClient postgresflex.DefaultAPI ) postgresflex.ApiListFlavorsRequest {
76- return apiClient .ListFlavors (ctx , model .ProjectId , model .Region ).Size (100 )
97+ req := apiClient .ListFlavors (ctx , model .ProjectId , model .Region )
98+
99+ if model .Limit != nil {
100+ req = req .Size (* model .Limit )
101+ } else {
102+ // the default page size is only 10
103+ req = req .Size (100 )
104+ }
105+
106+ return req
77107}
78108
79109func outputResult (p * print.Printer , outputFormat string , flavors []postgresflex.ListFlavors ) error {
0 commit comments