Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nothub committed May 1, 2024
1 parent 27548d2 commit b1b086f
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions buildinfo/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"path"
"runtime/debug"
"strings"
)

const unknown string = "unknown"
Expand All @@ -13,7 +14,7 @@ var name = unknown
var module = unknown

var version = unknown
var rev = unknown
var revision = unknown
var dirty = false

var arch = unknown
Expand All @@ -29,11 +30,12 @@ func init() {

name = path.Base(bi.Main.Path)
module = bi.Main.Path
version = bi.Main.Version

for _, kv := range bi.Settings {
switch kv.Key {
case "vcs.revision":
rev = kv.Value[:8]
revision = kv.Value[:8]
case "vcs.modified":
if kv.Value == "true" {
dirty = true
Expand All @@ -48,7 +50,7 @@ func init() {
}

if version == unknown {
version = rev
version = revision
}
}

Expand All @@ -64,14 +66,19 @@ func Version() string {
return version
}

func Revision() string {
return revision
}

func PrintInfos() {
fmt.Printf("%s %s %s",
Name(),
Version(),
fmt.Sprintf("%s-%s-%s", arch, os, compiler),
)
sb := strings.Builder{}
sb.WriteString(fmt.Sprintf("%s %s", Name(), Version()))
if Version() != Revision() {
sb.WriteString(fmt.Sprintf(" %s", Revision()))
}
sb.WriteString(fmt.Sprintf(" %s-%s-%s", arch, os, compiler))
if dirty {
fmt.Printf(" %s", "DIRTY")
sb.WriteString(" DIRTY")
}
fmt.Print("\n")
fmt.Println(sb.String())
}

0 comments on commit b1b086f

Please sign in to comment.