From 881d1407f77dd2988c065be6201f94ab64fe1ba9 Mon Sep 17 00:00:00 2001 From: Blaize Kaye Date: Sun, 8 Mar 2026 10:23:18 +1300 Subject: [PATCH 1/2] Moves version update requirement into version command only --- cmd/root.go | 69 +++++++++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 759a7bae..4b7101aa 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -60,39 +60,6 @@ var rootCmd = &cobra.Command{ Short: "Command line integration for Lagoon", Long: `Lagoon CLI. Manage your Lagoon hosted projects.`, DisableAutoGenTag: true, - PersistentPreRun: func(cmd *cobra.Command, args []string) { - if lagoonCLIConfig.UpdateCheckDisable { - skipUpdateCheck = true - } - if lagoonCLIConfig.StrictHostKeyChecking != "" { - strictHostKeyCheck = lagoonCLIConfig.StrictHostKeyChecking - } - if !skipUpdateCheck { - // Using code from https://github.com/drud/ddev/ - updateFile := filepath.Join(userPath, ".lagoon.update") - // Do periodic detection of whether an update is available for lagoon-cli users. - timeToCheckForUpdates, err := updatecheck.IsUpdateNeeded(updateFile, updateInterval) - if err != nil { - output.RenderInfo(fmt.Sprintf("Could not perform update check %v\n", err), outputOptions) - } - if timeToCheckForUpdates && isInternetActive() { - // Recreate the updatefile with current time so we won't do this again soon. - err = updatecheck.ResetUpdateTime(updateFile) - if err != nil { - output.RenderInfo(fmt.Sprintf("Failed to update updatecheck file %s\n", updateFile), outputOptions) - } - updateNeeded, updateURL, err := updatecheck.AvailableUpdates("uselagoon", "lagoon-cli", lagoonCLIVersion) - if err != nil { - output.RenderInfo("Could not check for updates. This is most often caused by a networking issue.\n", outputOptions) - output.RenderError(err.Error(), outputOptions) - return - } - if updateNeeded { - output.RenderInfo(fmt.Sprintf("A new update is available! please visit %s to download the update.\nFor upgrade help see %s\n\nIf installed using brew, upgrade using `brew upgrade lagoon`\n", updateURL, updateDocURL), outputOptions) - } - } - } - }, Run: func(cmd *cobra.Command, args []string) { if docsFlag { err := doc.GenMarkdownTree(cmd, "docs/commands") @@ -124,7 +91,7 @@ func isInternetActive() bool { } func init() { - cobra.OnInitialize(initConfig) + cobra.OnInitialize(initConfig, StrictHostKeyCheckInit) rootCmd.PersistentFlags().StringVarP(&cmdProjectName, "project", "p", "", "Specify a project to use") rootCmd.PersistentFlags().StringVarP(&cmdProjectEnvironment, "environment", "e", "", "Specify an environment to use") @@ -207,6 +174,34 @@ var versionCmd = &cobra.Command{ Use: "version", Short: "Version information", Run: func(cmd *cobra.Command, args []string) { + if lagoonCLIConfig.UpdateCheckDisable { + skipUpdateCheck = true + } + if !skipUpdateCheck { + // Using code from https://github.com/drud/ddev/ + updateFile := filepath.Join(userPath, ".lagoon.update") + // Do periodic detection of whether an update is available for lagoon-cli users. + timeToCheckForUpdates, err := updatecheck.IsUpdateNeeded(updateFile, updateInterval) + if err != nil { + output.RenderInfo(fmt.Sprintf("Could not perform update check %v\n", err), outputOptions) + } + if timeToCheckForUpdates && isInternetActive() { + // Recreate the updatefile with current time so we won't do this again soon. + err = updatecheck.ResetUpdateTime(updateFile) + if err != nil { + output.RenderInfo(fmt.Sprintf("Failed to update updatecheck file %s\n", updateFile), outputOptions) + } + updateNeeded, updateURL, err := updatecheck.AvailableUpdates("uselagoon", "lagoon-cli", lagoonCLIVersion) + if err != nil { + output.RenderInfo("Could not check for updates. This is most often caused by a networking issue.\n", outputOptions) + output.RenderError(err.Error(), outputOptions) + return + } + if updateNeeded { + output.RenderInfo(fmt.Sprintf("A new update is available! please visit %s to download the update.\nFor upgrade help see %s\n\nIf installed using brew, upgrade using `brew upgrade lagoon`\n", updateURL, updateDocURL), outputOptions) + } + } + } displayVersionInfo() }, } @@ -249,6 +244,12 @@ func initConfig() { } } +func StrictHostKeyCheckInit() { + if lagoonCLIConfig.StrictHostKeyChecking != "" { + strictHostKeyCheck = lagoonCLIConfig.StrictHostKeyChecking + } +} + func yesNo(message string) bool { if !forceAction { prompt := promptui.Select{ From 442318c1bfc0db42dfcaf9a6df40d60daf814d37 Mon Sep 17 00:00:00 2001 From: Blaize Kaye Date: Sun, 8 Mar 2026 10:31:21 +1300 Subject: [PATCH 2/2] Fixes visibility of function --- cmd/root.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 4b7101aa..ffbb5520 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -91,7 +91,7 @@ func isInternetActive() bool { } func init() { - cobra.OnInitialize(initConfig, StrictHostKeyCheckInit) + cobra.OnInitialize(initConfig, strictHostKeyCheckInit) rootCmd.PersistentFlags().StringVarP(&cmdProjectName, "project", "p", "", "Specify a project to use") rootCmd.PersistentFlags().StringVarP(&cmdProjectEnvironment, "environment", "e", "", "Specify an environment to use") @@ -244,7 +244,7 @@ func initConfig() { } } -func StrictHostKeyCheckInit() { +func strictHostKeyCheckInit() { if lagoonCLIConfig.StrictHostKeyChecking != "" { strictHostKeyCheck = lagoonCLIConfig.StrictHostKeyChecking }