Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cmd/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/supabase/cli/internal/functions/serve"
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/internal/utils/flags"
"github.com/supabase/cli/pkg/cast"
)

var (
Expand Down Expand Up @@ -106,9 +107,9 @@ var (
}

if len(inspectMode.Value) > 0 {
runtimeOption.InspectMode = utils.Ptr(serve.InspectMode(inspectMode.Value))
runtimeOption.InspectMode = cast.Ptr(serve.InspectMode(inspectMode.Value))
} else if inspectBrk {
runtimeOption.InspectMode = utils.Ptr(serve.InspectModeBrk)
runtimeOption.InspectMode = cast.Ptr(serve.InspectModeBrk)
}
if runtimeOption.InspectMode == nil && runtimeOption.InspectMain {
return fmt.Errorf("--inspect-main must be used together with one of these flags: [inspect inspect-mode]")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ require (
github.com/go-xmlfmt/xmlfmt v1.1.2
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/golangci/golangci-lint v1.61.0
github.com/google/go-cmp v0.6.0
github.com/google/go-github/v62 v62.0.0
github.com/google/go-querystring v1.1.0
github.com/google/uuid v1.6.0
Expand Down Expand Up @@ -169,7 +170,6 @@ require (
github.com/golangci/plugin-module-register v0.1.1 // indirect
github.com/golangci/revgrep v0.5.3 // indirect
github.com/golangci/unconvert v0.0.0-20240309020433-c5143eacb3ed // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/gordonklaus/ineffassign v0.1.0 // indirect
github.com/gorilla/css v1.0.0 // indirect
Expand Down
7 changes: 4 additions & 3 deletions internal/branches/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/internal/utils/flags"
"github.com/supabase/cli/pkg/api"
"github.com/supabase/cli/pkg/cast"
)

func TestCreateCommand(t *testing.T) {
Expand All @@ -36,7 +37,7 @@ func TestCreateCommand(t *testing.T) {
})
// Run test
err := Run(context.Background(), api.CreateBranchBody{
Region: utils.Ptr("sin"),
Region: cast.Ptr("sin"),
}, fsys)
// Check error
assert.NoError(t, err)
Expand All @@ -53,7 +54,7 @@ func TestCreateCommand(t *testing.T) {
ReplyError(net.ErrClosed)
// Run test
err := Run(context.Background(), api.CreateBranchBody{
Region: utils.Ptr("sin"),
Region: cast.Ptr("sin"),
}, fsys)
// Check error
assert.ErrorIs(t, err, net.ErrClosed)
Expand All @@ -70,7 +71,7 @@ func TestCreateCommand(t *testing.T) {
Reply(http.StatusServiceUnavailable)
// Run test
err := Run(context.Background(), api.CreateBranchBody{
Region: utils.Ptr("sin"),
Region: cast.Ptr("sin"),
}, fsys)
// Check error
assert.ErrorContains(t, err, "Unexpected error creating preview branch:")
Expand Down
3 changes: 2 additions & 1 deletion internal/functions/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/go-errors/errors"
"github.com/spf13/afero"
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/pkg/cast"
"github.com/supabase/cli/pkg/config"
"github.com/supabase/cli/pkg/function"
)
Expand Down Expand Up @@ -86,7 +87,7 @@ func GetFunctionConfig(slugs []string, importMapPath string, noVerifyJWT *bool,
function.ImportMap = utils.FallbackImportMapPath
}
if noVerifyJWT != nil {
function.VerifyJWT = utils.Ptr(!*noVerifyJWT)
function.VerifyJWT = cast.Ptr(!*noVerifyJWT)
}
functionConfig[name] = function
}
Expand Down
3 changes: 2 additions & 1 deletion internal/functions/deploy/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/supabase/cli/internal/testing/apitest"
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/pkg/api"
"github.com/supabase/cli/pkg/cast"
"github.com/supabase/cli/pkg/config"
)

Expand Down Expand Up @@ -323,7 +324,7 @@ func TestImportMapPath(t *testing.T) {
fsys := afero.NewMemMapFs()
require.NoError(t, afero.WriteFile(fsys, utils.FallbackImportMapPath, []byte("{}"), 0644))
// Run test
fc, err := GetFunctionConfig([]string{slug}, utils.FallbackImportMapPath, utils.Ptr(false), fsys)
fc, err := GetFunctionConfig([]string{slug}, utils.FallbackImportMapPath, cast.Ptr(false), fsys)
// Check error
assert.NoError(t, err)
assert.Equal(t, utils.FallbackImportMapPath, fc[slug].ImportMap)
Expand Down
3 changes: 2 additions & 1 deletion internal/functions/serve/serve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/supabase/cli/internal/testing/apitest"
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/pkg/cast"
)

func TestServeCommand(t *testing.T) {
Expand Down Expand Up @@ -100,7 +101,7 @@ func TestServeCommand(t *testing.T) {
Reply(http.StatusOK).
JSON(types.ContainerJSON{})
// Run test
err := Run(context.Background(), ".env", utils.Ptr(true), "import_map.json", RuntimeOption{}, fsys)
err := Run(context.Background(), ".env", cast.Ptr(true), "import_map.json", RuntimeOption{}, fsys)
// Check error
assert.ErrorIs(t, err, os.ErrNotExist)
})
Expand Down
9 changes: 5 additions & 4 deletions internal/init/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/supabase/cli/internal/testing/fstest"
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/pkg/cast"
)

func TestInitCommand(t *testing.T) {
Expand Down Expand Up @@ -70,7 +71,7 @@ func TestInitCommand(t *testing.T) {
// Setup in-memory fs
fsys := &afero.MemMapFs{}
// Run test
assert.NoError(t, Run(context.Background(), fsys, utils.Ptr(true), nil, utils.InitParams{}))
assert.NoError(t, Run(context.Background(), fsys, cast.Ptr(true), nil, utils.InitParams{}))
// Validate generated vscode settings
exists, err := afero.Exists(fsys, settingsPath)
assert.NoError(t, err)
Expand All @@ -84,7 +85,7 @@ func TestInitCommand(t *testing.T) {
// Setup in-memory fs
fsys := &afero.MemMapFs{}
// Run test
assert.NoError(t, Run(context.Background(), fsys, utils.Ptr(false), nil, utils.InitParams{}))
assert.NoError(t, Run(context.Background(), fsys, cast.Ptr(false), nil, utils.InitParams{}))
// Validate vscode settings file isn't generated
exists, err := afero.Exists(fsys, settingsPath)
assert.NoError(t, err)
Expand All @@ -98,7 +99,7 @@ func TestInitCommand(t *testing.T) {
// Setup in-memory fs
fsys := &afero.MemMapFs{}
// Run test
assert.NoError(t, Run(context.Background(), fsys, nil, utils.Ptr(true), utils.InitParams{}))
assert.NoError(t, Run(context.Background(), fsys, nil, cast.Ptr(true), utils.InitParams{}))
// Validate generated intellij deno config
exists, err := afero.Exists(fsys, denoPath)
assert.NoError(t, err)
Expand All @@ -109,7 +110,7 @@ func TestInitCommand(t *testing.T) {
// Setup in-memory fs
fsys := &afero.MemMapFs{}
// Run test
assert.NoError(t, Run(context.Background(), fsys, nil, utils.Ptr(false), utils.InitParams{}))
assert.NoError(t, Run(context.Background(), fsys, nil, cast.Ptr(false), utils.InitParams{}))
// Validate intellij deno config file isn't generated
exists, err := afero.Exists(fsys, denoPath)
assert.NoError(t, err)
Expand Down
9 changes: 5 additions & 4 deletions internal/storage/cp/cp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ import (
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/internal/utils/flags"
"github.com/supabase/cli/pkg/api"
"github.com/supabase/cli/pkg/cast"
"github.com/supabase/cli/pkg/fetcher"
"github.com/supabase/cli/pkg/storage"
)

var mockFile = storage.ObjectResponse{
Name: "abstract.pdf",
Id: utils.Ptr("9b7f9f48-17a6-4ca8-b14a-39b0205a63e9"),
UpdatedAt: utils.Ptr("2023-10-13T18:08:22.068Z"),
CreatedAt: utils.Ptr("2023-10-13T18:08:22.068Z"),
LastAccessedAt: utils.Ptr("2023-10-13T18:08:22.068Z"),
Id: cast.Ptr("9b7f9f48-17a6-4ca8-b14a-39b0205a63e9"),
UpdatedAt: cast.Ptr("2023-10-13T18:08:22.068Z"),
CreatedAt: cast.Ptr("2023-10-13T18:08:22.068Z"),
LastAccessedAt: cast.Ptr("2023-10-13T18:08:22.068Z"),
Metadata: &storage.ObjectMetadata{
ETag: `"887ea9be3c68e6f2fca7fd2d7c77d8fe"`,
Size: 82702,
Expand Down
9 changes: 5 additions & 4 deletions internal/storage/ls/ls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ import (
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/internal/utils/flags"
"github.com/supabase/cli/pkg/api"
"github.com/supabase/cli/pkg/cast"
"github.com/supabase/cli/pkg/fetcher"
"github.com/supabase/cli/pkg/storage"
)

var mockFile = storage.ObjectResponse{
Name: "abstract.pdf",
Id: utils.Ptr("9b7f9f48-17a6-4ca8-b14a-39b0205a63e9"),
UpdatedAt: utils.Ptr("2023-10-13T18:08:22.068Z"),
CreatedAt: utils.Ptr("2023-10-13T18:08:22.068Z"),
LastAccessedAt: utils.Ptr("2023-10-13T18:08:22.068Z"),
Id: cast.Ptr("9b7f9f48-17a6-4ca8-b14a-39b0205a63e9"),
UpdatedAt: cast.Ptr("2023-10-13T18:08:22.068Z"),
CreatedAt: cast.Ptr("2023-10-13T18:08:22.068Z"),
LastAccessedAt: cast.Ptr("2023-10-13T18:08:22.068Z"),
Metadata: &storage.ObjectMetadata{
ETag: `"887ea9be3c68e6f2fca7fd2d7c77d8fe"`,
Size: 82702,
Expand Down
9 changes: 5 additions & 4 deletions internal/storage/mv/mv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ import (
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/internal/utils/flags"
"github.com/supabase/cli/pkg/api"
"github.com/supabase/cli/pkg/cast"
"github.com/supabase/cli/pkg/fetcher"
"github.com/supabase/cli/pkg/storage"
)

var mockFile = storage.ObjectResponse{
Name: "abstract.pdf",
Id: utils.Ptr("9b7f9f48-17a6-4ca8-b14a-39b0205a63e9"),
UpdatedAt: utils.Ptr("2023-10-13T18:08:22.068Z"),
CreatedAt: utils.Ptr("2023-10-13T18:08:22.068Z"),
LastAccessedAt: utils.Ptr("2023-10-13T18:08:22.068Z"),
Id: cast.Ptr("9b7f9f48-17a6-4ca8-b14a-39b0205a63e9"),
UpdatedAt: cast.Ptr("2023-10-13T18:08:22.068Z"),
CreatedAt: cast.Ptr("2023-10-13T18:08:22.068Z"),
LastAccessedAt: cast.Ptr("2023-10-13T18:08:22.068Z"),
Metadata: &storage.ObjectMetadata{
ETag: `"887ea9be3c68e6f2fca7fd2d7c77d8fe"`,
Size: 82702,
Expand Down
9 changes: 5 additions & 4 deletions internal/storage/rm/rm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ import (
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/internal/utils/flags"
"github.com/supabase/cli/pkg/api"
"github.com/supabase/cli/pkg/cast"
"github.com/supabase/cli/pkg/fetcher"
"github.com/supabase/cli/pkg/storage"
)

var mockFile = storage.ObjectResponse{
Name: "abstract.pdf",
Id: utils.Ptr("9b7f9f48-17a6-4ca8-b14a-39b0205a63e9"),
UpdatedAt: utils.Ptr("2023-10-13T18:08:22.068Z"),
CreatedAt: utils.Ptr("2023-10-13T18:08:22.068Z"),
LastAccessedAt: utils.Ptr("2023-10-13T18:08:22.068Z"),
Id: cast.Ptr("9b7f9f48-17a6-4ca8-b14a-39b0205a63e9"),
UpdatedAt: cast.Ptr("2023-10-13T18:08:22.068Z"),
CreatedAt: cast.Ptr("2023-10-13T18:08:22.068Z"),
LastAccessedAt: cast.Ptr("2023-10-13T18:08:22.068Z"),
Metadata: &storage.ObjectMetadata{
ETag: `"887ea9be3c68e6f2fca7fd2d7c77d8fe"`,
Size: 82702,
Expand Down
3 changes: 2 additions & 1 deletion internal/utils/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/spf13/viper"
"github.com/supabase/cli/internal/utils/cloudflare"
supabase "github.com/supabase/cli/pkg/api"
"github.com/supabase/cli/pkg/cast"
)

const (
Expand Down Expand Up @@ -60,7 +61,7 @@ func FallbackLookupIP(ctx context.Context, host string) ([]string, error) {
func ResolveCNAME(ctx context.Context, host string) (string, error) {
// Ref: https://developers.cloudflare.com/1.1.1.1/encryption/dns-over-https/make-api-requests/dns-json
cf := cloudflare.NewCloudflareAPI()
data, err := cf.DNSQuery(ctx, cloudflare.DNSParams{Name: host, Type: Ptr(cloudflare.TypeCNAME)})
data, err := cf.DNSQuery(ctx, cloudflare.DNSParams{Name: host, Type: cast.Ptr(cloudflare.TypeCNAME)})
if err != nil {
return "", err
}
Expand Down
5 changes: 3 additions & 2 deletions internal/utils/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/go-errors/errors"
"github.com/supabase/cli/pkg/cast"
"golang.org/x/term"
)

Expand Down Expand Up @@ -78,10 +79,10 @@ func (c *Console) PromptYesNo(ctx context.Context, label string, def bool) (bool
func parseYesNo(s string) *bool {
s = strings.ToLower(s)
if s == "y" || s == "yes" {
return Ptr(true)
return cast.Ptr(true)
}
if s == "n" || s == "no" {
return Ptr(false)
return cast.Ptr(false)
}
return nil
}
Expand Down
4 changes: 0 additions & 4 deletions internal/utils/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,6 @@ func ValidateFunctionSlug(slug string) error {
return nil
}

func Ptr[T any](v T) *T {
return &v
}

func GetHostname() string {
host := Docker.DaemonHost()
if parsed, err := client.ParseHostURL(host); err == nil && parsed.Scheme == "tcp" {
Expand Down
3 changes: 2 additions & 1 deletion internal/utils/release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/h2non/gock"
"github.com/stretchr/testify/assert"
"github.com/supabase/cli/internal/testing/apitest"
"github.com/supabase/cli/pkg/cast"
)

func TestLatestRelease(t *testing.T) {
Expand All @@ -19,7 +20,7 @@ func TestLatestRelease(t *testing.T) {
gock.New("https://api.github.com").
Get("/repos/supabase/cli/releases/latest").
Reply(http.StatusOK).
JSON(github.RepositoryRelease{TagName: Ptr("v2")})
JSON(github.RepositoryRelease{TagName: cast.Ptr("v2")})
// Run test
version, err := GetLatestRelease(context.Background())
// Check error
Expand Down