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:
parent
a74b0bc679
commit
1e25ceab29
@ -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
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user