@@ -27,11 +27,13 @@ func ListCmd(ch *cmdutil.Helper) *cobra.Command {
2727 var flags struct {
2828 region string
2929 metal bool
30+ engine string
3031 }
3132
3233 cmd := & cobra.Command {
3334 Use : "list" ,
3435 Short : "List the sizes that are available for a PlanetScale database" ,
36+ Long : "List the sizes that are available for a PlanetScale database. Use --engine to specify the database engine type." ,
3537 Args : cobra .NoArgs ,
3638 Aliases : []string {"ls" },
3739 RunE : func (cmd * cobra.Command , args []string ) error {
@@ -41,9 +43,26 @@ func ListCmd(ch *cmdutil.Helper) *cobra.Command {
4143 return err
4244 }
4345
46+ // Parse the engine flag
47+ engine , err := parseDatabaseEngine (flags .engine )
48+ if err != nil {
49+ return err
50+ }
51+
52+ // Build the list options
53+ listOpts := []planetscale.ListOption {planetscale .WithRates ()}
54+ if flags .region != "" {
55+ listOpts = append (listOpts , planetscale .WithRegion (flags .region ))
56+ }
57+
58+ // Add engine-specific parameter for PostgreSQL
59+ if engine == planetscale .DatabaseEnginePostgres {
60+ listOpts = append (listOpts , planetscale .WithPostgreSQL ())
61+ }
62+
4463 clusterSKUs , err := client .Organizations .ListClusterSKUs (ctx , & planetscale.ListOrganizationClusterSKUsRequest {
4564 Organization : ch .Config .Organization ,
46- }, planetscale . WithRates (), planetscale . WithRegion ( flags . region ) )
65+ }, listOpts ... )
4766 if err != nil {
4867 return err
4968 }
@@ -54,11 +73,19 @@ func ListCmd(ch *cmdutil.Helper) *cobra.Command {
5473
5574 cmd .Flags ().StringVar (& flags .region , "region" , "" , "view cluster sizes and rates for a specific region" )
5675 cmd .Flags ().BoolVar (& flags .metal , "metal" , false , "view cluster sizes and rates for clusters with metal storage" )
76+ cmd .Flags ().StringVar (& flags .engine , "engine" , "mysql" , "The database engine to show cluster sizes for. Supported values: mysql, postgresql. Defaults to mysql." )
5777
5878 cmd .RegisterFlagCompletionFunc ("region" , func (cmd * cobra.Command , args []string , toComplete string ) ([]cobra.Completion , cobra.ShellCompDirective ) {
5979 return cmdutil .RegionsCompletionFunc (ch , cmd , args , toComplete )
6080 })
6181
82+ cmd .RegisterFlagCompletionFunc ("engine" , func (cmd * cobra.Command , args []string , toComplete string ) ([]cobra.Completion , cobra.ShellCompDirective ) {
83+ return []cobra.Completion {
84+ cobra .CompletionWithDesc ("mysql" , "A Vitess database" ),
85+ cobra .CompletionWithDesc ("postgresql" , "The fastest cloud Postgres" ),
86+ }, cobra .ShellCompDirectiveNoFileComp
87+ })
88+
6289 return cmd
6390}
6491
@@ -105,6 +132,17 @@ func toClusterSKU(clusterSKU *planetscale.ClusterSKU) *ClusterSKU {
105132 return cluster
106133}
107134
135+ func parseDatabaseEngine (engine string ) (planetscale.DatabaseEngine , error ) {
136+ switch engine {
137+ case "mysql" :
138+ return planetscale .DatabaseEngineMySQL , nil
139+ case "postgresql" , "postgres" :
140+ return planetscale .DatabaseEnginePostgres , nil
141+ default :
142+ return planetscale .DatabaseEngineMySQL , fmt .Errorf ("invalid database engine %q, supported values: mysql, postgresql" , engine )
143+ }
144+ }
145+
108146func toClusterSKUs (clusterSKUs []* planetscale.ClusterSKU , onlyMetal bool ) []* ClusterSKU {
109147 clusters := make ([]* ClusterSKU , 0 , len (clusterSKUs ))
110148
0 commit comments