// Output build info (version, commit, date and builtBy)
if versionFlag {
var buildInfo string
if date != "unknown" && builtBy != "unknown" {
buildInfo = fmt.Sprintf("Built\t\t%s by %s\n", date, builtBy)
}
if commit != "none" {
buildInfo = fmt.Sprintf("Commit:\t\t%s\n%s", commit, buildInfo)
}
if version == "dev" {
bi, ok := debug.ReadBuildInfo()
if ok {
version = bi.Main.Version
if strings.HasPrefix(version, "v") {
version = bi.Main.Version[1:]
}
if len(buildInfo) == 0 {
fmt.Printf("version %s\n", version)
os.Exit(0)
}
}
}
fmt.Printf("Version:\t%s\n%s", version, buildInfo)
os.Exit(0)
The idea being that in addition to setting a build "version" via Makefile builds, it would be really useful to support determining the version when a package is installed via go install.
From https://github.com/mgechev/revive/commit/b7d1908051ec9493485b3dcbf42b4565b7744e74:
The idea being that in addition to setting a build "version" via Makefile builds, it would be really useful to support determining the version when a package is installed via
go install
.