44 "os"
55
66 "github.com/joho/godotenv"
7+ "github.com/rios0rios0/cliforge/pkg/selfupdate"
78 "github.com/rios0rios0/terra/internal/domain/commands"
89 "github.com/rios0rios0/terra/internal/domain/entities"
910 logger "github.com/sirupsen/logrus"
@@ -16,6 +17,20 @@ import (
1617
1718var version = "dev"
1819
20+ // runUpdateCheck queries the cliforge selfupdate command for a newer version,
21+ // skipping local dev builds and the self-update / version subcommands to avoid
22+ // redundant GitHub API calls and noisy warnings.
23+ func runUpdateCheck (command * cobra.Command ) {
24+ if commands .TerraVersion == "dev" {
25+ return
26+ }
27+ switch command .Name () {
28+ case "self-update" , "version" :
29+ return
30+ }
31+ selfupdate .NewCommand ("rios0rios0" , "terra" , "terra" , commands .TerraVersion ).CheckForUpdates ()
32+ }
33+
1934// buildRootCommand creates and configures the root cobra command.
2035func buildRootCommand (rootController entities.Controller , enableFlagParsing bool ) * cobra.Command {
2136 bind := rootController .GetBind ()
@@ -24,6 +39,9 @@ func buildRootCommand(rootController entities.Controller, enableFlagParsing bool
2439 Use : bind .Use ,
2540 Short : bind .Short ,
2641 Long : bind .Long ,
42+ PersistentPreRun : func (command * cobra.Command , _ []string ) {
43+ runUpdateCheck (command )
44+ },
2745 Run : func (command * cobra.Command , arguments []string ) {
2846 rootController .Execute (command , arguments )
2947 },
0 commit comments