1
1
Fork 0
mirror of https://github.com/adammck/terraform-inventory synced 2024-05-12 06:16:07 +02:00

Add version info to binaries

This commit is contained in:
Adam Mckaig 2015-02-09 16:14:55 -05:00
parent d536bd0748
commit 0a27ca67d0
3 changed files with 34 additions and 0 deletions

View File

@ -7,6 +7,7 @@ import (
"path/filepath"
)
var version = flag.Bool("version", false, "print version information and exit")
var list = flag.Bool("list", false, "list mode")
var host = flag.String("host", "", "host mode")
@ -14,6 +15,11 @@ func main() {
flag.Parse()
file := flag.Arg(0)
if *version == true {
fmt.Printf("%s version %d\n", os.Args[0], versionInfo())
return
}
if file == "" {
fmt.Printf("Usage: %s [options] path\n", os.Args[0])
os.Exit(1)

15
version.go Normal file
View File

@ -0,0 +1,15 @@
package main
// Deliberately uninitialized. See below.
var build_version string
// versionInfo returns a string containing the version information of the
// current build. It's empty by default, but can be included as part of the
// build process by setting the main.build_version variable.
func versionInfo() string {
if build_version != "" {
return build_version
} else {
return "unknown"
}
}

13
version_test.go Normal file
View File

@ -0,0 +1,13 @@
package main
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestVersionInfo(t *testing.T) {
assert.Equal(t, "unknown", versionInfo())
build_version = "vXYZ"
assert.Equal(t, "vXYZ", versionInfo())
}