feat(version): enhance version command output with VCS revision and timestamp
This commit is contained in:
+21
-1
@@ -8,7 +8,9 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"runtime/debug"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/AlexxIT/go2rtc/pkg/shell"
|
"github.com/AlexxIT/go2rtc/pkg/shell"
|
||||||
"github.com/AlexxIT/go2rtc/pkg/yaml"
|
"github.com/AlexxIT/go2rtc/pkg/yaml"
|
||||||
@@ -36,7 +38,25 @@ func Init() {
|
|||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if version {
|
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)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user