refactor(app): streamline version info retrieval and formatting

This commit is contained in:
Sergey Krashevich
2024-05-12 06:46:45 +03:00
parent b7c11db604
commit eaba451a47
+14 -12
View File
@@ -38,25 +38,27 @@ func Init() {
flag.Parse() flag.Parse()
if version { if version {
vcsRevision := "" var vcsRevision string
vcsTime := time.Now().Local() vcsTime := time.Now()
if info, ok := debug.ReadBuildInfo(); ok { if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings { for _, setting := range info.Settings {
if setting.Key == "vcs.revision" { switch setting.Key {
if len(setting.Value) > 7 { case "vcs.revision":
vcsRevision = setting.Value[:7] vcsRevision = setting.Value
} else { if len(vcsRevision) > 7 {
vcsRevision = setting.Value vcsRevision = vcsRevision[:7]
} }
vcsRevision = "(" + vcsRevision + ")" vcsRevision = "(" + vcsRevision + ")"
} case "vcs.time":
if setting.Key == "vcs.time" { if parsedTime, err := time.Parse(time.RFC3339, setting.Value); err == nil {
vcsTime, _ = time.Parse(time.RFC3339, setting.Value) vcsTime = parsedTime.Local()
vcsTime = vcsTime.Local() }
} }
} }
} }
fmt.Printf("go2rtc version %s%s: %s %s/%s\n", Version, vcsRevision, vcsTime.Local().String(), runtime.GOOS, runtime.GOARCH)
fmt.Printf("go2rtc version %s%s: %s %s/%s\n", Version, vcsRevision, vcsTime.String(), runtime.GOOS, runtime.GOARCH)
os.Exit(0) os.Exit(0)
} }