From b7c11db60450699975e8a27dc85d98a6d3efa282 Mon Sep 17 00:00:00 2001 From: Sergey Krashevich Date: Sun, 12 May 2024 06:34:28 +0300 Subject: [PATCH] feat(version): enhance version command output with VCS revision and timestamp --- internal/app/app.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/internal/app/app.go b/internal/app/app.go index bc44a16f..6f3ccf72 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -8,7 +8,9 @@ import ( "os/exec" "path/filepath" "runtime" + "runtime/debug" "strings" + "time" "github.com/AlexxIT/go2rtc/pkg/shell" "github.com/AlexxIT/go2rtc/pkg/yaml" @@ -36,7 +38,25 @@ func Init() { flag.Parse() if version { - fmt.Printf("go2rtc version %s %s/%s\n", Version, runtime.GOOS, runtime.GOARCH) + vcsRevision := "" + vcsTime := time.Now().Local() + if info, ok := debug.ReadBuildInfo(); ok { + for _, setting := range info.Settings { + if setting.Key == "vcs.revision" { + if len(setting.Value) > 7 { + vcsRevision = setting.Value[:7] + } else { + vcsRevision = setting.Value + } + vcsRevision = "(" + vcsRevision + ")" + } + if setting.Key == "vcs.time" { + vcsTime, _ = time.Parse(time.RFC3339, setting.Value) + vcsTime = vcsTime.Local() + } + } + } + fmt.Printf("go2rtc version %s%s: %s %s/%s\n", Version, vcsRevision, vcsTime.Local().String(), runtime.GOOS, runtime.GOARCH) os.Exit(0) }