-
Notifications
You must be signed in to change notification settings - Fork 24
/
version.go
40 lines (34 loc) · 971 Bytes
/
version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package version
import (
"fmt"
"runtime"
"runtime/debug"
"strings"
)
// Version is this program's version string
var Version string
// UsageVersion introspects the process debug data for Go modules to return a
// version string.
func UsageVersion(includeDeps bool) string {
bi, ok := debug.ReadBuildInfo()
if !ok {
panic("failed to read BuildInfo because the program was compiled with Go " + runtime.Version())
}
if Version == "" {
// The version wasn't set by ldflags, so fallback to the Go module version.
// Although, this value is pretty much guaranteed to just be "(devel)".
Version = bi.Main.Version
}
if !includeDeps {
if Version == "(devel)" {
return "spicedb-operator development build (unknown exact version)"
}
return "spicedb-operator " + Version
}
var b strings.Builder
fmt.Fprintf(&b, "%s %s", bi.Path, Version)
for _, dep := range bi.Deps {
fmt.Fprintf(&b, "\n\t%s %s", dep.Path, dep.Version)
}
return b.String()
}