Documentation
¶
Overview ¶
/Users/EricGarciaMBP/Development/eng/cmd/version/version.go
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( Version = "dev" // Default value if not built with ldflags Commit = "none" // Default value Date = "unknown" // Default value )
These variables are set at build time using -ldflags They are exported so they can be used by root.go for the --version flag
View Source
var VersionCmd = &cobra.Command{ Use: "version", Short: "Print the version number of eng and check for updates", Long: `All software has versions. This is eng's. It shows the Git tag, commit hash, build date, Go version, OS/Arch, and checks GitHub for the latest available release.`, Run: func(cmd *cobra.Command, args []string) { fmt.Printf("eng version: %s\n", Version) fmt.Printf(" Git Commit: %s\n", Commit) fmt.Printf(" Build Date: %s\n", Date) fmt.Printf(" Go Version: %s\n", runtime.Version()) fmt.Printf(" OS/Arch: %s/%s\n", runtime.GOOS, runtime.GOARCH) fmt.Println() fmt.Println("Checking for latest version...") latestRelease, err := getLatestRelease(githubRepoOwner, githubRepoName) if err != nil { fmt.Printf(" Warning: Could not check for updates: %v\n", err) return } if latestRelease == nil || latestRelease.TagName == "" { fmt.Println(" Could not determine latest release version.") return } if Version == "dev" { fmt.Printf(" Currently running development version.\n") fmt.Printf(" Latest release is %s: %s\n", latestRelease.TagName, latestRelease.HTMLURL) return } currentSemVer, err := semver.NewVersion(Version) if err != nil { fmt.Printf(" Warning: Could not parse current version (%s) for comparison: %v\n", Version, err) fmt.Printf(" Latest release is %s: %s\n", latestRelease.TagName, latestRelease.HTMLURL) return } latestSemVer, err := semver.NewVersion(latestRelease.TagName) if err != nil { fmt.Printf(" Warning: Could not parse latest release tag (%s) for comparison: %v\n", latestRelease.TagName, err) return } if latestSemVer.GreaterThan(currentSemVer) { fmt.Printf(" A newer version is available: %s\n", latestRelease.TagName) fmt.Printf(" Get it here: %s\n", latestRelease.HTMLURL) } else if latestSemVer.Equal(currentSemVer) { fmt.Println(" You are running the latest version.") } else { fmt.Printf(" You are running a version newer than the latest release (%s).\n", latestRelease.TagName) } }, }
VersionCmd represents the version command
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.