mirror of
https://github.com/nikdoof/hapz2m.git
synced 2026-01-29 22:38:23 +00:00
Use VCS version stamp from Go 1.24
Go 1.24 now adds a human readable version to BuildInfo, similar to the output for `git describe`. Also output version in log on startup.
This commit is contained in:
@@ -68,36 +68,20 @@ func parseConfig(fname string) (cfg *config, err error) {
|
||||
}
|
||||
|
||||
func readVcsRevision() string {
|
||||
ver := ""
|
||||
dirty := false
|
||||
if info, ok := debug.ReadBuildInfo(); ok {
|
||||
for _, s := range info.Settings {
|
||||
switch s.Key {
|
||||
case "vcs.revision":
|
||||
if len(s.Value) >= 8 {
|
||||
ver = s.Value[:8]
|
||||
} else {
|
||||
ver = s.Value
|
||||
}
|
||||
|
||||
case "vcs.modified":
|
||||
dirty = s.Value == "true"
|
||||
}
|
||||
}
|
||||
if dirty {
|
||||
ver += "-dirty"
|
||||
}
|
||||
return ver
|
||||
return info.Main.Version
|
||||
}
|
||||
return "?"
|
||||
}
|
||||
|
||||
func main() {
|
||||
versionStr := fmt.Sprintf("hapz2m version %s", readVcsRevision())
|
||||
|
||||
flag.Usage = func() {
|
||||
fmt.Fprintf(flag.CommandLine.Output(), "hapz2m version %s\n"+
|
||||
fmt.Fprintf(flag.CommandLine.Output(), versionStr+"\n"+
|
||||
"HomeKit <-> zigbee2mqtt Bridge\n"+
|
||||
"\nUsage: %s [options...]\n",
|
||||
readVcsRevision(), filepath.Base(os.Args[0]))
|
||||
filepath.Base(os.Args[0]))
|
||||
flag.PrintDefaults()
|
||||
}
|
||||
|
||||
@@ -141,6 +125,8 @@ func main() {
|
||||
|
||||
br.Interfaces = cfg.Interfaces
|
||||
|
||||
log.Println(versionStr)
|
||||
|
||||
err = br.ConnectMQTT()
|
||||
if err != nil {
|
||||
log.Printf("cannot connect to MQTT: %s", err)
|
||||
|
||||
Reference in New Issue
Block a user