// "version" sub-command: display version information // SPDX-License-Identifier: GPL-3.0-or-later // Copyright (C) 2021-2025 Simon Ruderich package main import ( "fmt" "log" "runtime/debug" ) func MainVersion() error { info, ok := debug.ReadBuildInfo() if !ok { log.Fatal("ReadBuildInfo failed") } var vcsRev, vcsDirty, vcsTime, goos, goarch string for _, x := range info.Settings { switch x.Key { case "vcs.revision": vcsRev = x.Value[:7] case "vcs.modified": if x.Value == "true" { vcsDirty = "-dirty" } case "vcs.time": vcsTime = x.Value[:10] // "2006-01-02" case "GOOS": goos = x.Value case "GOARCH": goarch = x.Value } } fmt.Printf("safcm %s%s %s, compiled with %s %s/%s\n", vcsRev, vcsDirty, vcsTime, info.GoVersion, goos, goarch) return nil } // vi: set noet ts=4 sw=4 sts=4: