mirror of
https://github.com/mgechev/revive.git
synced 2024-11-24 08:32:22 +02:00
Avoids missing version description when using go install (#600)
This commit is contained in:
parent
9c30b4479c
commit
b7d1908051
32
main.go
32
main.go
@ -6,6 +6,7 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
@ -213,13 +214,30 @@ func init() {
|
||||
|
||||
// Output build info (version, commit, date and builtBy)
|
||||
if versionFlag {
|
||||
fmt.Printf(
|
||||
"Version:\t%s\nCommit:\t\t%s\nBuilt\t\t%s by %s\n",
|
||||
version,
|
||||
commit,
|
||||
date,
|
||||
builtBy,
|
||||
)
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user