mirror of
https://github.com/mgechev/revive.git
synced 2025-07-15 01:04:40 +02:00
Avoids missing version description when using go install (#600)
This commit is contained in:
committed by
GitHub
parent
9c30b4479c
commit
b7d1908051
32
main.go
32
main.go
@ -6,6 +6,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime/debug"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
@ -213,13 +214,30 @@ func init() {
|
|||||||
|
|
||||||
// Output build info (version, commit, date and builtBy)
|
// Output build info (version, commit, date and builtBy)
|
||||||
if versionFlag {
|
if versionFlag {
|
||||||
fmt.Printf(
|
var buildInfo string
|
||||||
"Version:\t%s\nCommit:\t\t%s\nBuilt\t\t%s by %s\n",
|
if date != "unknown" && builtBy != "unknown" {
|
||||||
version,
|
buildInfo = fmt.Sprintf("Built\t\t%s by %s\n", date, builtBy)
|
||||||
commit,
|
}
|
||||||
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)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user