Skip to content

Commit

Permalink
Merge pull request #928 from tursodatabase/glauber/group-replicate-qol
Browse files Browse the repository at this point in the history
QoL: improvements for group location add
  • Loading branch information
glommer authored Dec 2, 2024
2 parents b96a72b + 3f1fa45 commit 81f642b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions internal/cmd/db_replicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,15 @@ 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")
}

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)
Expand Down
14 changes: 12 additions & 2 deletions internal/cmd/group_locations.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var groupLocationsListCmd = &cobra.Command{
var groupLocationAddCmd = &cobra.Command{
Use: "add <group-name> <...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]
Expand All @@ -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)
Expand Down

0 comments on commit 81f642b

Please sign in to comment.