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:
parent
d536bd0748
commit
0a27ca67d0
6
main.go
6
main.go
@ -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
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
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())
|
||||
}
|
Loading…
Reference in New Issue
Block a user