Skip to content
This repository was archived by the owner on Oct 31, 2023. It is now read-only.

Commit a272647

Browse files
committed
Put version into CLI
1 parent 64fdded commit a272647

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
dist/
2+
13
# For testing:
24
config.hcl

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
VERSION := 0.1.0
2+
13
# Note that I'd love to use goreleaser for this but they don't quite
24
# have the hooks yet to be able to merge in gon support. Ideally they'd
35
# just integrate natively in some way.
46
build: clean
57
mkdir -p dist
6-
GOOS=darwin GOARCH=amd64 go build -o ./dist/gon ./cmd/gon
8+
GOOS=darwin GOARCH=amd64 go build -ldflags "-X main.version=$(VERSION)" -o ./dist/gon ./cmd/gon
79
.PHONY: build
810

911
# release will package the distribution packages, sign, and notarize

cmd/gon/main.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,29 @@ import (
1919
"github.com/mitchellh/gon/sign"
2020
)
2121

22+
// Set by build process
23+
var (
24+
version string
25+
)
26+
2227
func main() {
2328
os.Exit(realMain())
2429
}
2530

2631
func realMain() int {
32+
// Look for version
33+
for _, v := range os.Args[1:] {
34+
v = strings.TrimLeft(v, "-")
35+
if v == "v" || v == "version" {
36+
if version == "" {
37+
version = "dev"
38+
}
39+
40+
fmt.Printf("version %s\n", version)
41+
return 0
42+
}
43+
}
44+
2745
var logLevel string
2846
var logJSON bool
2947
flags := flag.NewFlagSet(os.Args[0], flag.ExitOnError)

0 commit comments

Comments
 (0)