Skip to content

Commit

Permalink
Add -V flag to print version
Browse files Browse the repository at this point in the history
It's hard to know which version of ssm-env you have post-install. This
adds a -V flag to print the version.
  • Loading branch information
aengelas committed Dec 12, 2023
1 parent e0c837d commit 70be7a2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
.PHONY: test
.DEFAULT_GOAL := bin/ssm-env

ARGS :=

version := $(shell git describe --tags --match 'v*')

.PHONY: run
run:
CGO_ENABLED=0 go run -ldflags "-X main.version=$(version)" . $(ARGS)

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

.PHONY: test
test:
go test -race $(shell go list ./... | grep -v /vendor/)
15 changes: 12 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,24 @@ var TemplateFuncs = template.FuncMap{
"toUpper": strings.ToUpper,
}

var version string

func main() {
var (
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")
decrypt = flag.Bool("with-decryption", false, "Will attempt to decrypt the parameter, and set the env var as plaintext")
nofail = flag.Bool("no-fail", false, "Don't fail if error retrieving parameter")
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")
decrypt = flag.Bool("with-decryption", false, "Will attempt to decrypt the parameter, and set the env var as plaintext")
nofail = flag.Bool("no-fail", false, "Don't fail if error retrieving parameter")
print_version = flag.Bool("V", false, "Print the version and exit")
)
flag.Parse()
args := flag.Args()

if *print_version {
fmt.Printf("%s\n", version)

return
}

if len(args) <= 0 {
flag.Usage()
os.Exit(1)
Expand Down

0 comments on commit 70be7a2

Please sign in to comment.