diff --git a/cmd/branches.go b/cmd/branches.go index 077d69cc37..1f12f8727b 100644 --- a/cmd/branches.go +++ b/cmd/branches.go @@ -30,9 +30,6 @@ var ( Short: "Manage Supabase preview branches", } - branchRegion = utils.EnumFlag{ - Allowed: awsRegions(), - } persistent bool withData bool notifyURL string @@ -49,7 +46,7 @@ var ( } cmdFlags := cmd.Flags() if cmdFlags.Changed("region") { - body.Region = &branchRegion.Value + body.Region = ®ion.Value } if cmdFlags.Changed("size") { body.DesiredInstanceSize = (*api.CreateBranchBodyDesiredInstanceSize)(&size.Value) @@ -206,7 +203,7 @@ func init() { branchFlags := branchesCmd.PersistentFlags() branchFlags.StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.") createFlags := branchCreateCmd.Flags() - createFlags.Var(&branchRegion, "region", "Select a region to deploy the branch database.") + createFlags.Var(®ion, "region", "Select a region to deploy the branch database.") createFlags.Var(&size, "size", "Select a desired instance size for the branch database.") createFlags.BoolVar(&persistent, "persistent", false, "Whether to create a persistent branch.") createFlags.BoolVar(&withData, "with-data", false, "Whether to clone production data to the branch database.") diff --git a/cmd/projects.go b/cmd/projects.go index 2ab5d7d2de..93a75fb20b 100644 --- a/cmd/projects.go +++ b/cmd/projects.go @@ -2,7 +2,6 @@ package cmd import ( "os" - "sort" "github.com/spf13/afero" "github.com/spf13/cobra" @@ -30,7 +29,7 @@ var ( orgId string dbPassword string region = utils.EnumFlag{ - Allowed: awsRegions(), + Allowed: utils.AwsRegions(), } size = utils.EnumFlag{ Allowed: []string{ @@ -153,12 +152,3 @@ func init() { projectsCmd.AddCommand(projectsApiKeysCmd) rootCmd.AddCommand(projectsCmd) } - -func awsRegions() []string { - result := make([]string, len(utils.CurrentProfile.ProjectRegions)) - for i, region := range utils.CurrentProfile.ProjectRegions { - result[i] = string(region) - } - sort.Strings(result) - return result -} diff --git a/internal/utils/profile.go b/internal/utils/profile.go index 1910f30b75..723b52fa87 100644 --- a/internal/utils/profile.go +++ b/internal/utils/profile.go @@ -3,6 +3,7 @@ package utils import ( "context" "fmt" + "sort" "strings" "github.com/go-errors/errors" @@ -128,3 +129,12 @@ func getProfileName(fsys afero.Fs) string { return prof } } + +func AwsRegions() []string { + result := make([]string, len(allProfiles[0].ProjectRegions)) + for i, region := range allProfiles[0].ProjectRegions { + result[i] = string(region) + } + sort.Strings(result) + return result +}