Skip to content

Commit

Permalink
feat: suggest upgrade when cli version is outdated
Browse files Browse the repository at this point in the history
  • Loading branch information
sweatybridge committed May 16, 2024
1 parent 1c88d20 commit 28152be
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/supabase/cli/internal/services"
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/internal/utils/flags"
"golang.org/x/mod/semver"
)

const (
Expand Down Expand Up @@ -137,11 +138,27 @@ func Execute() {
if err := rootCmd.Execute(); err != nil {
panic(err)
}
if utils.CmdSuggestion != utils.SuggestDebugFlag {
if vf := rootCmd.Flag("version"); vf != nil && vf.Changed {
version, err := utils.GetLatestRelease(rootCmd.Context())
if err != nil {
panic(err)
}
utils.CmdSuggestion = suggestUpgrade(version)
}
if len(utils.CmdSuggestion) > 0 && utils.CmdSuggestion != utils.SuggestDebugFlag {
fmt.Fprintln(os.Stderr, utils.CmdSuggestion)
}
}

func suggestUpgrade(version string) string {
if semver.Compare(version, "v"+utils.Version) <= 0 {
return ""
}
const guide = "https://supabase.com/docs/guides/cli/getting-started#updating-the-supabase-cli"
return fmt.Sprintf(`A new version of Supabase CLI is available: %s
Follow our guide to upgrade: %s`, utils.Aqua(version), utils.Bold(guide))
}

func recoverAndExit() {
err := recover()
if err == nil {
Expand Down

0 comments on commit 28152be

Please sign in to comment.