mirror of
https://github.com/nikdoof/hapz2m.git
synced 2026-01-30 10:28:21 +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 {
|
func readVcsRevision() string {
|
||||||
ver := ""
|
|
||||||
dirty := false
|
|
||||||
if info, ok := debug.ReadBuildInfo(); ok {
|
if info, ok := debug.ReadBuildInfo(); ok {
|
||||||
for _, s := range info.Settings {
|
return info.Main.Version
|
||||||
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 "?"
|
return "?"
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
versionStr := fmt.Sprintf("hapz2m version %s", readVcsRevision())
|
||||||
|
|
||||||
flag.Usage = func() {
|
flag.Usage = func() {
|
||||||
fmt.Fprintf(flag.CommandLine.Output(), "hapz2m version %s\n"+
|
fmt.Fprintf(flag.CommandLine.Output(), versionStr+"\n"+
|
||||||
"HomeKit <-> zigbee2mqtt Bridge\n"+
|
"HomeKit <-> zigbee2mqtt Bridge\n"+
|
||||||
"\nUsage: %s [options...]\n",
|
"\nUsage: %s [options...]\n",
|
||||||
readVcsRevision(), filepath.Base(os.Args[0]))
|
filepath.Base(os.Args[0]))
|
||||||
flag.PrintDefaults()
|
flag.PrintDefaults()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,6 +125,8 @@ func main() {
|
|||||||
|
|
||||||
br.Interfaces = cfg.Interfaces
|
br.Interfaces = cfg.Interfaces
|
||||||
|
|
||||||
|
log.Println(versionStr)
|
||||||
|
|
||||||
err = br.ConnectMQTT()
|
err = br.ConnectMQTT()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("cannot connect to MQTT: %s", err)
|
log.Printf("cannot connect to MQTT: %s", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user