Skip to content

Commit

Permalink
version
Browse files Browse the repository at this point in the history
  • Loading branch information
Listener430 committed Dec 13, 2024
1 parent 0f79d1c commit ea7fc1b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
11 changes: 6 additions & 5 deletions cmd/cmd_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}

Expand Down
23 changes: 16 additions & 7 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)
}
1 change: 0 additions & 1 deletion pkg/config/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ func processEnvVars(cliConfig *schema.CliConfiguration) error {
} else {
cliConfig.Version.Check.Enabled = enabled
}
cliConfig.Version.Check.Enabled = enabled
}

return nil
Expand Down

0 comments on commit ea7fc1b

Please sign in to comment.