From f3bead80bcec45c7eda1911e0180469934004c79 Mon Sep 17 00:00:00 2001 From: Glauber Costa Date: Wed, 27 Nov 2024 15:23:51 -0500 Subject: [PATCH] separate AWS regions from Fly regions --- internal/cmd/db_locations.go | 39 ++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/internal/cmd/db_locations.go b/internal/cmd/db_locations.go index 03a3abfd..07283cd6 100644 --- a/internal/cmd/db_locations.go +++ b/internal/cmd/db_locations.go @@ -3,6 +3,7 @@ package cmd import ( "fmt" "sort" + "strings" "github.com/spf13/cobra" "github.com/tursodatabase/turso-cli/internal" @@ -37,24 +38,46 @@ var regionsCmd = &cobra.Command{ columns := make([]interface{}, 0) - var ids []string - ids = maps.Keys(locations) - sort.Strings(ids) + ids := maps.Keys(locations) + + awsIds := make([]string, 0, len(ids)) + flyIds := make([]string, 0, len(ids)) + + for _, id := range ids { + if strings.HasPrefix(id, "aws-") { + awsIds = append(awsIds, id) + } else { + flyIds = append(flyIds, id) + } + } + + sort.Strings(awsIds) + sort.Strings(flyIds) + columns = append(columns, "ID↓") columns = append(columns, "LOCATION") - tbl := turso.LocationsTable(columns) + flyTbl := turso.LocationsTable(columns) + awsTbl := turso.LocationsTable(columns) - for _, location := range ids { + fmt.Println(internal.Emph("Fly.io Regions:")) + for _, location := range flyIds { description := locations[location] if location == closest { description = fmt.Sprintf("%s [default]", description) - tbl.AddRow(internal.Emph(location), internal.Emph(description)) + flyTbl.AddRow(internal.Emph(location), internal.Emph(description)) } else { - tbl.AddRow(location, description) + flyTbl.AddRow(location, description) } } - tbl.Print() + flyTbl.Print() + + fmt.Println(internal.Emph("\nAWS (beta) Regions:")) + for _, location := range awsIds { + description := locations[location] + awsTbl.AddRow(location, description) + } + awsTbl.Print() return nil }, }