v0.22.1 cli flag and behavior, and test output improvement
This commit is contained in:
1 parent
71d1b82f83
commit
4eba6fc834
89 files changed
+1531
-661
No files matched your search
@@ -1,6 +1,9 @@
|
||||
package version
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"runtime/debug"
|
||||
)
|
||||
|
||||
var (
|
||||
// Version is the application version, set at compile time via -ldflags
|
||||
@@ -11,11 +14,28 @@ var (
|
||||
BuildTime = "unknown"
|
||||
)
|
||||
|
||||
// init fills what -ldflags left unset from the build info: `go install
|
||||
// module@version` stamps the module version, a build in a checkout the commit.
|
||||
func init() {
|
||||
info, ok := debug.ReadBuildInfo()
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if v := info.Main.Version; Version == "dev" && v != "" && v != "(devel)" {
|
||||
Version = v
|
||||
}
|
||||
for _, s := range info.Settings {
|
||||
switch {
|
||||
case s.Key == "vcs.revision" && GitCommit == "unknown":
|
||||
GitCommit = s.Value[:min(len(s.Value), 12)]
|
||||
case s.Key == "vcs.time" && BuildTime == "unknown":
|
||||
BuildTime = s.Value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// String returns a detailed, formatted version string including commit and build time
|
||||
func String() string {
|
||||
if Version == "dev" {
|
||||
return fmt.Sprintf("dev (commit: %s, built: %s)", GitCommit, BuildTime)
|
||||
}
|
||||
return fmt.Sprintf("%s (commit: %s, built: %s)", Version, GitCommit, BuildTime)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user