From 4f385eaee4c5c2e917dae2486117f5025e117b37 Mon Sep 17 00:00:00 2001 From: Uzair Ali <72073401+uzaxirr@users.noreply.github.com> Date: Tue, 30 Apr 2024 06:29:13 +0530 Subject: [PATCH 1/5] Aliases for DB software --- cmd/database/database_create.go | 45 +++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/cmd/database/database_create.go b/cmd/database/database_create.go index ca31fb15..d673672e 100644 --- a/cmd/database/database_create.go +++ b/cmd/database/database_create.go @@ -3,6 +3,7 @@ package database import ( "fmt" "os" + "strings" "github.com/civo/civogo" "github.com/civo/cli/common" @@ -87,45 +88,51 @@ var dbCreateCmd = &cobra.Command{ dbVersions, err := client.ListDBVersions() if err != nil { - utility.Error("Unable to list database versions %s", err) + utility.Error("Failed to fetch database versions: %s", err) os.Exit(1) } - if software == "" { - software = "MySQL" - } + software = strings.ToLower(software) + softwareIsValid := false + softwareVersionIsValid := false - if softwareVersion == "" && software == "MySQL" { - softwareVersion = "8.0" + validSoftwares := map[string][]string{ + "mysql": {"mysql", "my", "sql"}, + "postgresql": {"postgresql", "psql"}, } - if software == "PostgreSQL" && softwareVersion == "" { - softwareVersion = "14" + apiSoftwareNames := map[string]string{ + "mysql": "MySQL", + "postgresql": "PostgreSQL", } - softwareIsValid := false - softwareVersionIsValid := false - if software != "" { - for swName, version := range dbVersions { - if swName == software { + canonicalSoftwareName := "" + for swName, aliases := range validSoftwares { + for _, alias := range aliases { + if alias == software { softwareIsValid = true - for i, v := range version { - if v.SoftwareVersion == version[i].SoftwareVersion { + canonicalSoftwareName = apiSoftwareNames[swName] + for _, v := range dbVersions[canonicalSoftwareName] { + if v.SoftwareVersion == softwareVersion { softwareVersionIsValid = true + break } } } - } } if !softwareIsValid { - utility.Error("The provided software name is not valid. Make sure you use correct capitalization (e.g. MySQL, PostgreSQL)") + utility.Error("The provided software name is not valid. Make sure you use correct capitalization (e.g., MySQL, PostgreSQL)") os.Exit(1) } if !softwareVersionIsValid { - utility.Error("The provided software version is not valid") + if softwareVersion == "" { + utility.Error(fmt.Sprintf("No version specified for %s. Please provide a version using --version flag. For example, civo database create db-psql --software psql --version 14.", canonicalSoftwareName)) + } else { + utility.Error("The provided software version is not valid. Please check the available versions for the specified software.") + } os.Exit(1) } @@ -136,7 +143,7 @@ var dbCreateCmd = &cobra.Command{ Nodes: nodes, FirewallID: firewallID, FirewallRules: rulesFirewall, - Software: software, + Software: canonicalSoftwareName, SoftwareVersion: softwareVersion, Region: client.Region, } From b672f2650e5875f60f871107e45edb5862036c5a Mon Sep 17 00:00:00 2001 From: Uzair Ali <72073401+uzaxirr@users.noreply.github.com> Date: Mon, 6 May 2024 14:50:20 +0530 Subject: [PATCH 2/5] rm mysql alias --- cmd/database/database_create.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/database/database_create.go b/cmd/database/database_create.go index d673672e..0eed68c6 100644 --- a/cmd/database/database_create.go +++ b/cmd/database/database_create.go @@ -97,7 +97,7 @@ var dbCreateCmd = &cobra.Command{ softwareVersionIsValid := false validSoftwares := map[string][]string{ - "mysql": {"mysql", "my", "sql"}, + "mysql": {"mysql"}, "postgresql": {"postgresql", "psql"}, } From 571d287df67b1d98989d411cc1bce75464743161 Mon Sep 17 00:00:00 2001 From: Uzair Ali <72073401+uzaxirr@users.noreply.github.com> Date: Thu, 16 May 2024 19:19:48 +0530 Subject: [PATCH 3/5] Grammer correction --- cmd/database/database_create.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/database/database_create.go b/cmd/database/database_create.go index 0eed68c6..c159e3e4 100644 --- a/cmd/database/database_create.go +++ b/cmd/database/database_create.go @@ -123,13 +123,13 @@ var dbCreateCmd = &cobra.Command{ } if !softwareIsValid { - utility.Error("The provided software name is not valid. Make sure you use correct capitalization (e.g., MySQL, PostgreSQL)") + utility.Error("The provided software name is not valid. Make sure you use correct capitalization (eg: MySQL, PostgreSQL)") os.Exit(1) } if !softwareVersionIsValid { if softwareVersion == "" { - utility.Error(fmt.Sprintf("No version specified for %s. Please provide a version using --version flag. For example, civo database create db-psql --software psql --version 14.", canonicalSoftwareName)) + utility.Error(fmt.Sprintf("No version specified for %s. Please provide a version using --version flag. For example, civo database create db-psql --software psql --version 14", canonicalSoftwareName)) } else { utility.Error("The provided software version is not valid. Please check the available versions for the specified software.") } From 1fd5c040416fcb3c6c6ea0b9fd94989988c6a838 Mon Sep 17 00:00:00 2001 From: Uzair Ali <72073401+uzaxirr@users.noreply.github.com> Date: Fri, 17 May 2024 15:43:47 +0530 Subject: [PATCH 4/5] rm caps --- cmd/database/database_create.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/database/database_create.go b/cmd/database/database_create.go index c159e3e4..6960f000 100644 --- a/cmd/database/database_create.go +++ b/cmd/database/database_create.go @@ -123,7 +123,7 @@ var dbCreateCmd = &cobra.Command{ } if !softwareIsValid { - utility.Error("The provided software name is not valid. Make sure you use correct capitalization (eg: MySQL, PostgreSQL)") + utility.Error("The provided software name is not valid. Make sure you use correct capitalization (eg: mysql, postgresql") os.Exit(1) } From 54a4527370068e44ac29d96aee7f8906879038eb Mon Sep 17 00:00:00 2001 From: Uzair Ali <72073401+uzaxirr@users.noreply.github.com> Date: Fri, 17 May 2024 16:29:34 +0530 Subject: [PATCH 5/5] change err msg --- cmd/database/database_create.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/database/database_create.go b/cmd/database/database_create.go index 6960f000..02e7fe89 100644 --- a/cmd/database/database_create.go +++ b/cmd/database/database_create.go @@ -123,7 +123,7 @@ var dbCreateCmd = &cobra.Command{ } if !softwareIsValid { - utility.Error("The provided software name is not valid. Make sure you use correct capitalization (eg: mysql, postgresql") + utility.Error("The provided software name is not valid. valid options are mysql, psql or postgresql") os.Exit(1) }