generated from thazelart/golang-cli-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.go
46 lines (36 loc) · 1.02 KB
/
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
41
42
43
44
45
46
//go:generate bash get_build_info.sh
package version
import (
// using blank import for embed as it is only used inside comments
_ "embed"
"fmt"
"runtime"
)
var (
// GitCommit returns the git commit that was compiled.
//go:embed commit.txt
gitCommit string
// Version returns the main version number that is being run at the moment.
//go:embed version.txt
version string
// BuildDate returns the date the binary was built
//go:embed build_date.txt
buildDate string
)
// GoVersion returns the version of the go runtime used to compile the binary
var goVersion = runtime.Version()
// OsArch returns the os and arch used to build the binary
var osArch = fmt.Sprintf("%s %s", runtime.GOOS, runtime.GOARCH)
// generateOutput return the output of the version command
func generateOutput() string {
return fmt.Sprintf(`bracket-creator - %s
Git Commit: %s
Build date: %s
Go version: %s
OS / Arch : %s
`, version, gitCommit, buildDate, goVersion, osArch)
}
// Print the current version
func Print() {
fmt.Println(generateOutput())
}