Skip to content
Open
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
22 changes: 16 additions & 6 deletions apps/cli-go/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/url"
"os"
"os/signal"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -188,15 +189,17 @@ func Execute() {
if executedCmd != nil {
ctx = executedCmd.Context()
}
version, err := checkUpgrade(ctx, afero.NewOsFs())
if err != nil {
fmt.Fprintln(utils.GetDebugLogger(), err)
}
if hint := utils.SuggestClaudePlugin(); hint != "" {
fmt.Fprintln(os.Stderr, hint)
}
if semver.Compare(version, "v"+utils.Version) > 0 {
fmt.Fprintln(os.Stderr, suggestUpgrade(version))
if updateNotifierEnabled() {
version, err := checkUpgrade(ctx, afero.NewOsFs())
if err != nil {
fmt.Fprintln(utils.GetDebugLogger(), err)
}
if semver.Compare(version, "v"+utils.Version) > 0 {
fmt.Fprintln(os.Stderr, suggestUpgrade(version))
}
}
if len(utils.CmdSuggestion) > 0 {
fmt.Fprintln(os.Stderr, utils.CmdSuggestion)
Expand Down Expand Up @@ -239,6 +242,13 @@ func exitCode(err error) int {
return 0
}

func updateNotifierEnabled() bool {
// Read the env directly instead of viper: the upgrade check also runs for
// --help and --version, which skip the cobra initializer that binds env vars.
disabled, _ := strconv.ParseBool(os.Getenv("SUPABASE_NO_UPDATE_NOTIFIER"))
return !disabled
}

func checkUpgrade(ctx context.Context, fsys afero.Fs) (string, error) {
if shouldFetchRelease(fsys) {
version, err := utils.GetLatestRelease(ctx)
Expand Down
19 changes: 19 additions & 0 deletions apps/cli-go/cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,25 @@ func TestCommandAnalyticsContext(t *testing.T) {
assert.NotEmpty(t, ctx.RunID)
}

func TestUpdateNotifierEnabled(t *testing.T) {
for value, wantEnabled := range map[string]bool{
"": true,
"0": true,
"false": true,
"1": false,
"true": false,
"t": false,
"TRUE": false,
"yes": true,
} {
t.Run("value "+value, func(t *testing.T) {
t.Setenv("SUPABASE_NO_UPDATE_NOTIFIER", value)

assert.Equal(t, wantEnabled, updateNotifierEnabled())
})
}
}

func TestCommandName(t *testing.T) {
root := &cobra.Command{Use: "supabase"}
parent := &cobra.Command{Use: "db"}
Expand Down