Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions cmd/completion/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions cmd/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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]")
Expand All @@ -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]")
Expand Down