From ea7fc1b0a2f11459964ceee5a59b03d8929c1a0b Mon Sep 17 00:00:00 2001 From: Andrey Kalmykov Date: Fri, 13 Dec 2024 20:22:49 +0600 Subject: [PATCH] version --- cmd/cmd_utils.go | 11 ++++++----- cmd/version.go | 23 ++++++++++++++++------- pkg/config/utils.go | 1 - 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/cmd/cmd_utils.go b/cmd/cmd_utils.go index a962f4d17..41a3246d8 100644 --- a/cmd/cmd_utils.go +++ b/cmd/cmd_utils.go @@ -470,12 +470,13 @@ func CheckForAtmosUpdateAndPrintMessage(cliConfig schema.CliConfiguration) { // If the versions differ, print the update message if latestVersion != currentVersion { u.PrintMessageToUpgradeToAtmosLatestRelease(latestVersion) + } + + // Update the cache to mark the current timestamp + cacheCfg.LastChecked = time.Now().Unix() + if saveErr := cfg.SaveCache(cacheCfg); saveErr != nil { + u.LogWarning(cliConfig, fmt.Sprintf("Unable to save cache: %s", saveErr)) - // Update the cache to mark the current timestamp - cacheCfg.LastChecked = time.Now().Unix() - if saveErr := cfg.SaveCache(cacheCfg); saveErr != nil { - u.LogWarning(cliConfig, fmt.Sprintf("Unable to save cache: %s", saveErr)) - } } } diff --git a/cmd/version.go b/cmd/version.go index 5146f4ff3..9b11e207a 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -13,6 +13,8 @@ import ( "github.com/cloudposse/atmos/pkg/version" ) +var checkFlag bool + var versionCmd = &cobra.Command{ Use: "version", Short: "Print the CLI version", @@ -29,18 +31,25 @@ var versionCmd = &cobra.Command{ u.PrintMessage(fmt.Sprintf("\U0001F47D Atmos %s on %s/%s", version.Version, runtime.GOOS, runtime.GOARCH)) fmt.Println() - // Check for the latest Atmos release on GitHub - latestReleaseTag, err := u.GetLatestGitHubRepoRelease("cloudposse", "atmos") - if err == nil && latestReleaseTag != "" { - latestRelease := strings.TrimPrefix(latestReleaseTag, "v") - currentRelease := strings.TrimPrefix(version.Version, "v") - if latestRelease != currentRelease { - u.PrintMessageToUpgradeToAtmosLatestRelease(latestRelease) + if checkFlag { + // Check for the latest Atmos release on GitHub + latestReleaseTag, err := u.GetLatestGitHubRepoRelease("cloudposse", "atmos") + if err == nil && latestReleaseTag != "" { + latestRelease := strings.TrimPrefix(latestReleaseTag, "v") + currentRelease := strings.TrimPrefix(version.Version, "v") + if latestRelease != currentRelease { + u.PrintMessageToUpgradeToAtmosLatestRelease(latestRelease) + } } + return } + + // Check for the cache and print update message + CheckForAtmosUpdateAndPrintMessage(cliConfig) }, } func init() { + versionCmd.Flags().BoolVarP(&checkFlag, "check", "c", false, "Run additional checks after displaying version info") RootCmd.AddCommand(versionCmd) } diff --git a/pkg/config/utils.go b/pkg/config/utils.go index bf4404e5a..060a1cf2a 100644 --- a/pkg/config/utils.go +++ b/pkg/config/utils.go @@ -380,7 +380,6 @@ func processEnvVars(cliConfig *schema.CliConfiguration) error { } else { cliConfig.Version.Check.Enabled = enabled } - cliConfig.Version.Check.Enabled = enabled } return nil