Skip to content

Commit

Permalink
Avoids missing version description when using go install (#600)
Browse files Browse the repository at this point in the history
  • Loading branch information
jefersonf authored Oct 17, 2021
1 parent 9c30b44 commit b7d1908
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"runtime/debug"
"strings"

"github.com/fatih/color"
Expand Down Expand Up @@ -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)
}
}

0 comments on commit b7d1908

Please sign in to comment.