Skip to content

Commit

Permalink
Add build info
Browse files Browse the repository at this point in the history
  • Loading branch information
5nord committed Nov 6, 2024
1 parent cae931f commit 9bae8eb
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package main

import (
"fmt"
"strings"

"runtime/debug"

"github.com/spf13/cobra"
)
Expand All @@ -19,5 +22,24 @@ func init() {
}

func versionInfo(cmd *cobra.Command, args []string) {
fmt.Printf("ntt %v, commit %v, built at %v\n", version, commit, date)
if version == "dev" {
info, ok := debug.ReadBuildInfo()
if ok && strings.HasPrefix(info.Main.Version, "v") {
version = info.Main.Version
}
for _, s := range info.Settings {
switch s.Key {
case "vcs.time":
date = s.Value
case "vcs.revision":
commit = s.Value
case "vcs.modified":
if s.Value == "true" {
commit += "-dirty"
}
}
}
}

fmt.Printf("ntt %v, commit %s, built at %s\n", version, commit, date)
}

0 comments on commit 9bae8eb

Please sign in to comment.