diff --git a/apps/cli-go/cmd/root.go b/apps/cli-go/cmd/root.go index f83eb6d11b..227de8656a 100644 --- a/apps/cli-go/cmd/root.go +++ b/apps/cli-go/cmd/root.go @@ -8,6 +8,7 @@ import ( "net/url" "os" "os/signal" + "strconv" "strings" "sync" "time" @@ -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) @@ -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) diff --git a/apps/cli-go/cmd/root_test.go b/apps/cli-go/cmd/root_test.go index fa7c6f39d7..ee52d8fc54 100644 --- a/apps/cli-go/cmd/root_test.go +++ b/apps/cli-go/cmd/root_test.go @@ -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"}