Skip to content

Commit

Permalink
Merge pull request #366 from uzaxirr/db-versions
Browse files Browse the repository at this point in the history
Add Support for DB version list
  • Loading branch information
uzaxirr authored Feb 24, 2024
2 parents 0121af5 + 851c2b7 commit 4c96844
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func init() {
DBCmd.AddCommand(dbEngineCmd)
DBCmd.AddCommand(dbBackupCmd)
DBCmd.AddCommand(dbRestoreCmd)
DBCmd.AddCommand(dbVersionListCmd)

dbCredentialCmd.Flags().BoolVarP(&connectionString, "connection-string", "c", false, "show the connection string for the database")

Expand Down
52 changes: 52 additions & 0 deletions cmd/database/database_version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package database

import (
"github.com/civo/cli/common"
"github.com/civo/cli/config"
"github.com/civo/cli/utility"
"github.com/spf13/cobra"
"os"
)

var dbVersionListCmd = &cobra.Command{
Use: "versions",
Aliases: []string{"version"},
Example: `civo db versions`,
Short: "List all the available database versions",
Run: func(cmd *cobra.Command, args []string) {
utility.EnsureCurrentRegion()

client, err := config.CivoAPIClient()
if err != nil {
utility.Error("Creating the connection to Civo's API failed with %s", err)
os.Exit(1)
}

if common.RegionSet != "" {
client.Region = common.RegionSet
}

dbVersions, err := client.ListDBVersions()
if err != nil {
utility.Error("%s", err)
os.Exit(1)
}

ow := utility.NewOutputWriter()

for dbName, versionDetails := range dbVersions {
ow.StartLine()
ow.AppendDataWithLabel("name", dbName, "Name")
ow.AppendDataWithLabel("version", versionDetails[0].SoftwareVersion, "version")
}

switch common.OutputFormat {
case "json":
ow.WriteMultipleObjectsJSON(common.PrettySet)
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
ow.WriteTable()
}
},
}

0 comments on commit 4c96844

Please sign in to comment.