Documentation
¶
Overview ¶
Package version implements the 'eng version' command, which displays the application's version information and checks for available updates.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // Version holds the application's version string (e.g., "0.1.0" or "dev"). Version = "dev" // Commit holds the Git commit hash from which the application was built. Commit = "none" // Date holds the build date of the application. Date = "unknown" )
Build-time variables These variables are populated during the build process using ldflags.
View Source
var VersionCmd = &cobra.Command{ Use: "version", Short: "Print the version number of eng and check for updates", Long: `Displays the application's version, build commit, build date, Go version, and target OS/Architecture. It also checks the GitHub repository for the latest official release and compares it with the currently running version.`, Run: func(cmd *cobra.Command, args []string) { log.Info("eng version: %s", Version) log.Message(" Git Commit: %s", Commit) log.Message(" Build Date: %s", Date) log.Message(" Go Version: %s", runtime.Version()) log.Message(" OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH) log.Message("") sp := utils.NewSpinner("Checking for latest version...") sp.Start() latestRelease, err := getLatestRelease(githubRepoOwner, githubRepoName) sp.Stop() if err != nil { log.Warn("Could not check for updates: %v", err) return } if latestRelease == nil || latestRelease.TagName == "" { log.Warn("Could not determine the latest release version from GitHub.") return } if Version == "dev" { log.Info("Currently running development version.") log.Info("Latest release is %s: %s", latestRelease.TagName, latestRelease.HTMLURL) return } currentSemVer, err := semver.NewVersion(Version) if err != nil { log.Warn("Could not parse current version (%s) for comparison: %v", Version, err) log.Info("Latest release is %s: %s", latestRelease.TagName, latestRelease.HTMLURL) return } latestSemVer, err := semver.NewVersion(latestRelease.TagName) if err != nil { log.Warn("Could not parse latest release tag (%s) as semver: %v", latestRelease.TagName, err) log.Info("Latest release tag is: %s", latestRelease.TagName) log.Info(" Release page: %s", latestRelease.HTMLURL) return } if latestSemVer.GreaterThan(currentSemVer) { log.Success("A newer version is available: %s", latestRelease.TagName) log.Info(" Get it here: %s", latestRelease.HTMLURL) } else if latestSemVer.Equal(currentSemVer) { log.Success("You are running the latest version.") } else { log.Info("You are running a version newer than the latest official release (%s).", latestRelease.TagName) } }, }
VersionCmd represents the Cobra command for 'eng version'. It displays the current version details and checks GitHub for the latest release.
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.