From 3f1fa4514cb076e07c867a2c65ca7149eedf38aa Mon Sep 17 00:00:00 2001 From: Glauber Costa Date: Thu, 28 Nov 2024 16:39:43 -0500 Subject: [PATCH] QoL: improvements for group location add Show the location selector when adding locations to a group too. Also cleanup the function, that has an argument that is never used. --- internal/cmd/db_replicate.go | 4 ++-- internal/cmd/group_locations.go | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/internal/cmd/db_replicate.go b/internal/cmd/db_replicate.go index 4582fce1..4427c1d0 100644 --- a/internal/cmd/db_replicate.go +++ b/internal/cmd/db_replicate.go @@ -172,7 +172,7 @@ func getReplicateLocation(client *turso.Client, args []string, database turso.Da return "", err } - location := pickLocation(database.Name, locations, database.Regions) + location := pickLocation(locations, database.Regions) if location == "" { return "", fmt.Errorf("you must specify a database location ID to replicate it") } @@ -180,7 +180,7 @@ func getReplicateLocation(client *turso.Client, args []string, database turso.Da return location, nil } -func pickLocation(dbName string, locations map[string]string, exclude []string) string { +func pickLocation(locations map[string]string, exclude []string) string { fmt.Printf("%s", internal.Emph("Available locations:\n")) excluded := make(map[string]bool) diff --git a/internal/cmd/group_locations.go b/internal/cmd/group_locations.go index ec2a4f38..b839a101 100644 --- a/internal/cmd/group_locations.go +++ b/internal/cmd/group_locations.go @@ -53,7 +53,7 @@ var groupLocationsListCmd = &cobra.Command{ var groupLocationAddCmd = &cobra.Command{ Use: "add <...location-code>", Short: "Add locations to a database group", - Args: cobra.MinimumNArgs(2), + Args: cobra.MinimumNArgs(1), ValidArgsFunction: locationsAddArgs, RunE: func(cmd *cobra.Command, args []string) error { groupName := args[0] @@ -75,8 +75,18 @@ var groupLocationAddCmd = &cobra.Command{ for _, location := range group.Locations { alreadyExistingLocations[location] = true } + available, err := locations(client) + if err != nil { + return err + } + + locations := make([]string, 0) + if len(args) > 1 { + locations = append(locations, args[1:]...) + } else { + locations = append(locations, pickLocation(available, group.Locations)) + } - locations := args[1:] for _, location := range locations { if !isValidLocation(client, location) { return fmt.Errorf("location '%s' is not a valid one", location)