Skip to content

Commit 70be7a2

Browse files
committed
Add -V flag to print version
It's hard to know which version of ssm-env you have post-install. This adds a -V flag to print the version.
1 parent e0c837d commit 70be7a2

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

Makefile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
.PHONY: test
1+
.DEFAULT_GOAL := bin/ssm-env
2+
3+
ARGS :=
4+
5+
version := $(shell git describe --tags --match 'v*')
6+
7+
.PHONY: run
8+
run:
9+
CGO_ENABLED=0 go run -ldflags "-X main.version=$(version)" . $(ARGS)
210

311
bin/ssm-env: *.go
4-
CGO_ENABLED=0 go build -o $@ .
12+
CGO_ENABLED=0 go build -ldflags "-X main.version=$(version)" -o $@ .
513

14+
.PHONY: test
615
test:
716
go test -race $(shell go list ./... | grep -v /vendor/)

main.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,24 @@ var TemplateFuncs = template.FuncMap{
4343
"toUpper": strings.ToUpper,
4444
}
4545

46+
var version string
47+
4648
func main() {
4749
var (
48-
template = flag.String("template", DefaultTemplate, "The template used to determine what the SSM parameter name is for an environment variable. When this template returns an empty string, the env variable is not an SSM parameter")
49-
decrypt = flag.Bool("with-decryption", false, "Will attempt to decrypt the parameter, and set the env var as plaintext")
50-
nofail = flag.Bool("no-fail", false, "Don't fail if error retrieving parameter")
50+
template = flag.String("template", DefaultTemplate, "The template used to determine what the SSM parameter name is for an environment variable. When this template returns an empty string, the env variable is not an SSM parameter")
51+
decrypt = flag.Bool("with-decryption", false, "Will attempt to decrypt the parameter, and set the env var as plaintext")
52+
nofail = flag.Bool("no-fail", false, "Don't fail if error retrieving parameter")
53+
print_version = flag.Bool("V", false, "Print the version and exit")
5154
)
5255
flag.Parse()
5356
args := flag.Args()
5457

58+
if *print_version {
59+
fmt.Printf("%s\n", version)
60+
61+
return
62+
}
63+
5564
if len(args) <= 0 {
5665
flag.Usage()
5766
os.Exit(1)

0 commit comments

Comments
 (0)