From 6ba9d27c50f43e54da0ddf5512ab2040a9170529 Mon Sep 17 00:00:00 2001 From: uzair Date: Sat, 24 Feb 2024 02:17:10 +0530 Subject: [PATCH 1/4] Add Support for DB version list --- cmd/database/database.go | 1 + cmd/database/database_version.go | 52 ++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 cmd/database/database_version.go diff --git a/cmd/database/database.go b/cmd/database/database.go index 89939309..c386ab73 100644 --- a/cmd/database/database.go +++ b/cmd/database/database.go @@ -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") diff --git a/cmd/database/database_version.go b/cmd/database/database_version.go new file mode 100644 index 00000000..4a4e352e --- /dev/null +++ b/cmd/database/database_version.go @@ -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() + } + }, +} From 2d9eae1e39b24dd6a70be03a7975ba3f845136ed Mon Sep 17 00:00:00 2001 From: uzair Date: Sat, 24 Feb 2024 02:31:10 +0530 Subject: [PATCH 2/4] unset region in client --- cmd/database/database_version.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/cmd/database/database_version.go b/cmd/database/database_version.go index 4a4e352e..147b6e8c 100644 --- a/cmd/database/database_version.go +++ b/cmd/database/database_version.go @@ -22,10 +22,6 @@ var dbVersionListCmd = &cobra.Command{ os.Exit(1) } - if common.RegionSet != "" { - client.Region = common.RegionSet - } - dbVersions, err := client.ListDBVersions() if err != nil { utility.Error("%s", err) From eae43923b2ae8828cf4f73a490d675418f97f2a7 Mon Sep 17 00:00:00 2001 From: uzair Date: Sat, 24 Feb 2024 02:32:08 +0530 Subject: [PATCH 3/4] unset region in client --- cmd/database/database_version.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/database/database_version.go b/cmd/database/database_version.go index 147b6e8c..a4e31605 100644 --- a/cmd/database/database_version.go +++ b/cmd/database/database_version.go @@ -14,7 +14,6 @@ var dbVersionListCmd = &cobra.Command{ 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 { From 851c2b709069a9b10b70e53ce55adcecf8b30b2d Mon Sep 17 00:00:00 2001 From: uzair Date: Sat, 24 Feb 2024 03:12:06 +0530 Subject: [PATCH 4/4] set region in client --- cmd/database/database_version.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmd/database/database_version.go b/cmd/database/database_version.go index a4e31605..4a4e352e 100644 --- a/cmd/database/database_version.go +++ b/cmd/database/database_version.go @@ -14,6 +14,7 @@ var dbVersionListCmd = &cobra.Command{ 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 { @@ -21,6 +22,10 @@ var dbVersionListCmd = &cobra.Command{ os.Exit(1) } + if common.RegionSet != "" { + client.Region = common.RegionSet + } + dbVersions, err := client.ListDBVersions() if err != nil { utility.Error("%s", err)