buildinfo/buildInfo.go

53 lines
920 B
Go
Raw Permalink Normal View History

2022-08-29 02:33:53 +02:00
package buildinfo
type buildInfo struct {
Name string
Version string
Commit string
BuildTime string
OS string
Arch string
ShowDeps bool
Deps []Dep
}
2022-08-29 10:30:43 +02:00
type Options struct {
BuildTime bool
Commit bool
OsArch bool
Deps bool
}
2022-08-29 02:33:53 +02:00
type Dep struct {
Name string
Version string
Sum string
}
2022-08-29 10:30:43 +02:00
func newBuildInfo(options Options) *buildInfo {
buildTime := iff(options.BuildTime, BuildTime, "")
commit := iff(options.Commit, Commit, "")
os := iff(options.OsArch, OS, "")
arch := iff(options.OsArch, Arch, "")
showDeps := iff(options.Deps, true, false)
2022-08-29 02:33:53 +02:00
return &buildInfo{
2022-08-29 10:30:43 +02:00
Name: Name,
Version: Version,
Deps: dependencies,
Commit: commit,
BuildTime: buildTime,
OS: os,
Arch: arch,
ShowDeps: showDeps,
}
}
func iff[T any](condition bool, trueValue, falseValue T) T {
if condition {
return trueValue
2022-08-29 02:33:53 +02:00
}
2022-08-29 10:30:43 +02:00
return falseValue
2022-08-29 02:33:53 +02:00
}