Skip to content

Commit

Permalink
chore: apply PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
avallete committed Sep 20, 2024
1 parent 044ba61 commit d660a36
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 32 deletions.
34 changes: 34 additions & 0 deletions cmd/start.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,46 @@
package cmd

import (
"fmt"
"os"
"sort"
"strings"

"github.com/spf13/afero"
"github.com/spf13/cobra"
"github.com/supabase/cli/internal/start"
"github.com/supabase/cli/internal/utils"
)

func validateExcludedContainers(excludedContainers []string) {
// Validate excluded containers
validContainers := start.ExcludableContainers()
var invalidContainers []string

for _, e := range excludedContainers {
found := false
for _, v := range validContainers {
if strings.EqualFold(e, v) {
found = true
break
}
}
if !found {
invalidContainers = append(invalidContainers, e)
}
}

if len(invalidContainers) > 0 {
// Sort the names list so it's easier to visually spot the one you looking for
sort.Strings(validContainers)
warning := fmt.Sprintf("%s The following container names are not valid to exclude: %s\nValid containers to exclude are: %s\n",
utils.Yellow("Warning:"),
utils.Aqua(strings.Join(invalidContainers, ", ")),
utils.Aqua(strings.Join(validContainers, ", ")))
fmt.Fprint(os.Stderr, warning)
}
}

var (
allowedContainers = start.ExcludableContainers()
excludedContainers []string
Expand All @@ -19,6 +52,7 @@ var (
Use: "start",
Short: "Start containers for Supabase local development",
RunE: func(cmd *cobra.Command, args []string) error {
validateExcludedContainers(excludedContainers)
return start.Run(cmd.Context(), afero.NewOsFs(), excludedContainers, ignoreHealthCheck)
},
}
Expand Down
33 changes: 1 addition & 32 deletions internal/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"os"
"path"
"path/filepath"
"sort"
"strconv"
"strings"
"text/template"
Expand Down Expand Up @@ -44,39 +43,9 @@ func suggestUpdateCmd(serviceImages map[string]string) string {
return cmd
}

func validateExcludedContainers(excludedContainers []string) {
// Validate excluded containers
validContainers := ExcludableContainers()
var invalidContainers []string

for _, e := range excludedContainers {
found := false
for _, v := range validContainers {
if strings.EqualFold(e, v) {
found = true
break
}
}
if !found {
invalidContainers = append(invalidContainers, e)
}
}

if len(invalidContainers) > 0 {
// Sort the names list so it's easier to visually spot the one you looking for
sort.Strings(validContainers)
warning := fmt.Sprintf("%s The following container names are not valid to exclude: %s\nValid containers to exclude are: %s\n",
utils.Yellow("Warning:"),
utils.Aqua(strings.Join(invalidContainers, ", ")),
utils.Aqua(strings.Join(validContainers, ", ")))
fmt.Fprint(os.Stderr, warning)
}
}

func Run(ctx context.Context, fsys afero.Fs, excludedContainers []string, ignoreHealthCheck bool) error {
// Sanity checks.
{
validateExcludedContainers(excludedContainers)
if err := utils.LoadConfigFS(fsys); err != nil {
return err
}
Expand Down Expand Up @@ -859,7 +828,7 @@ EOF
}

// Start Storage.
if isStorageEnabled && !isContainerExcluded(utils.Config.Storage.Image, excluded) {
if isStorageEnabled {
dockerStoragePath := "/mnt"
if _, err := utils.DockerStart(
ctx,
Expand Down

0 comments on commit d660a36

Please sign in to comment.