1
0
mirror of https://github.com/go-task/task.git synced 2024-12-04 10:24:45 +02:00

fix: version check (#1663)

* fix: version check

* refactor following review
This commit is contained in:
Valentin Maerten 2024-05-20 22:48:05 +02:00 committed by GitHub
parent a74b0bc679
commit 1e25ceab29
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 14 deletions

View File

@ -58,7 +58,7 @@ func run() error {
entrypoint := flags.Entrypoint
if flags.Version {
fmt.Printf("Task version: %s\n", ver.GetVersion())
fmt.Printf("Task version: %s\n", ver.GetVersionWithSum())
return nil
}

View File

@ -5,21 +5,25 @@ import (
"runtime/debug"
)
var version = ""
func GetVersion() string {
if version != "" {
return version
}
var (
version = ""
sum = ""
)
func init() {
info, ok := debug.ReadBuildInfo()
if !ok || info.Main.Version == "" {
return "unknown"
version = "unknown"
} else {
version = info.Main.Version
sum = info.Main.Sum
}
ver := info.Main.Version
if info.Main.Sum != "" {
ver += fmt.Sprintf(" (%s)", info.Main.Sum)
}
return ver
}
func GetVersion() string {
return version
}
func GetVersionWithSum() string {
return fmt.Sprintf("%s (%s)", version, sum)
}