1
1
mirror of https://github.com/adammck/terraform-inventory synced 2024-11-22 15:52:01 +01: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

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

15
version.go Normal 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

@ -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())
}