diff --git a/cmd/completion/completion.go b/cmd/completion/completion.go index f0307305..58b168a1 100644 --- a/cmd/completion/completion.go +++ b/cmd/completion/completion.go @@ -445,6 +445,29 @@ func (c *Completion) PostgresListCompletion(cmd *cobra.Command, args []string, t sort.Strings(names) return names, cobra.ShellCompDirectiveNoFileComp } +func (c *Completion) PostgresListStorageClassesCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + request := database.NewGetPostgresPartitionsParams() + response, err := c.cloud.Database.GetPostgresPartitions(request, nil) + if err != nil { + return nil, cobra.ShellCompDirectiveError + } + + // get the value of the partition flag, if provided + partitionName, _ := cmd.Flags().GetString("partition") + + var scs []string + for n, pp := range response.Payload { + for sc := range pp.AllowedStorageClasses { + if partitionName != "" && partitionName != n { + // when the partion flag was provided, ignore storage classes of other postgres partitions + continue + } + scs = append(scs, sc) + } + } + sort.Strings(scs) + return scs, cobra.ShellCompDirectiveNoFileComp +} func (c *Completion) ProductOptionsCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { var options []string diff --git a/cmd/postgres.go b/cmd/postgres.go index 4acb521a..c11fdbea 100644 --- a/cmd/postgres.go +++ b/cmd/postgres.go @@ -289,6 +289,7 @@ postgres=# genericcli.Must(postgresCreateCmd.RegisterFlagCompletionFunc("project", c.comp.ProjectListCompletion)) genericcli.Must(postgresCreateCmd.RegisterFlagCompletionFunc("partition", c.comp.PostgresListPartitionsCompletion)) genericcli.Must(postgresCreateCmd.RegisterFlagCompletionFunc("version", c.comp.PostgresListVersionsCompletion)) + genericcli.Must(postgresCreateCmd.RegisterFlagCompletionFunc("storage-class", c.comp.PostgresListStorageClassesCompletion)) // CreateStandby postgresCreateStandbyCmd.Flags().StringP("primary-postgres-id", "", "", "id of the primary database") @@ -310,6 +311,7 @@ postgres=# genericcli.Must(postgresCreateStandbyCmd.MarkFlagRequired("backup-config")) genericcli.Must(postgresCreateStandbyCmd.RegisterFlagCompletionFunc("primary-postgres-id", c.comp.PostgresListCompletion)) genericcli.Must(postgresCreateStandbyCmd.RegisterFlagCompletionFunc("partition", c.comp.PostgresListPartitionsCompletion)) + genericcli.Must(postgresCreateStandbyCmd.RegisterFlagCompletionFunc("storage-class", c.comp.PostgresListStorageClassesCompletion)) // PromoteToPrimary postgresPromoteToPrimaryCmd.Flags().BoolP("synchronous", "", false, "make the replication synchronous") @@ -328,6 +330,7 @@ postgres=# genericcli.Must(postgresRestoreCmd.MarkFlagRequired("source-postgres-id")) genericcli.Must(postgresRestoreCmd.RegisterFlagCompletionFunc("source-postgres-id", c.comp.PostgresListCompletion)) genericcli.Must(postgresRestoreCmd.RegisterFlagCompletionFunc("partition", c.comp.PostgresListPartitionsCompletion)) + genericcli.Must(postgresRestoreCmd.RegisterFlagCompletionFunc("storage-class", c.comp.PostgresListStorageClassesCompletion)) // Update postgresUpdateCmd.Flags().IntP("replicas", "", 1, "replicas of the database [optional]") @@ -345,6 +348,8 @@ postgres=# postgresUpdateCmd.Flags().StringP("backup-config", "", "", "backup config to use. REQUIRES A POD RESTART TO TAKE EFFECT [optional]") postgresUpdateCmd.Flags().StringP("storage-class", "", "", "the storage class to use for the database. REQUIRES ADMIN PRIVILEGES [optional]") + genericcli.Must(postgresUpdateCmd.RegisterFlagCompletionFunc("storage-class", c.comp.PostgresListStorageClassesCompletion)) + // List postgresListCmd.Flags().StringP("id", "", "", "postgres id to filter [optional]") postgresListCmd.Flags().StringP("description", "", "", "description to filter [optional]")