File tree Expand file tree Collapse file tree 4 files changed +26
-3
lines changed
Expand file tree Collapse file tree 4 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -3,17 +3,19 @@ TARGET ?= darwin
33ARCH ?= amd64
44EXT ?= ""
55DOCKER_REPO =itsdalmo/ssm-sh
6+ TRAVIS_TAG ?= ref-$(shell git rev-parse --short HEAD)
7+ LDFLAGS =-ldflags "-X=main.version=$(TRAVIS_TAG ) "
68SRC =$(shell find . -type f -name '* .go' -not -path "./vendor/* ")
79
810default : test
911
1012run : test
1113 @echo " == Run =="
12- go run main.go
14+ go run $( LDFLAGS ) main.go
1315
1416build : test
1517 @echo " == Build =="
16- go build -o $(BINARY_NAME ) -v
18+ go build -o $(BINARY_NAME ) -v $( LDFLAGS )
1719
1820test :
1921 @echo " == Test =="
@@ -40,6 +42,6 @@ build-docker:
4042
4143build-release :
4244 @echo " == Release build =="
43- CGO_ENABLED=0 GOOS=$(TARGET ) GOARCH=$(ARCH ) go build -o $(BINARY_NAME ) -$(TARGET ) -$(ARCH )$(EXT ) -v
45+ CGO_ENABLED=0 GOOS=$(TARGET ) GOARCH=$(ARCH ) go build $( LDFLAGS ) -o $(BINARY_NAME ) -$(TARGET ) -$(ARCH )$(EXT ) -v
4446
4547.PHONY : default build test build-docker run-docker build-release
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package command
33var Command RootCommand
44
55type RootCommand struct {
6+ Version func () `short:"v" long:"version" description:"Print the version and exit."`
67 List ListCommand `command:"list" alias:"ls" description:"List managed instances."`
78 Shell ShellCommand `command:"shell" alias:"sh" description:"Start an interactive shell."`
89 Run RunCommand `command:"run" description:"Run a command on the targeted instances."`
Original file line number Diff line number Diff line change 1+ package command
2+
3+ import (
4+ "fmt"
5+ "os"
6+ )
7+
8+ // CommandVersion (overridden in main.go)
9+ var CommandVersion = "unknown"
10+
11+ func init () {
12+ Command .Version = func () {
13+ fmt .Println (CommandVersion )
14+ os .Exit (0 )
15+ }
16+ }
Original file line number Diff line number Diff line change @@ -6,7 +6,11 @@ import (
66 "os"
77)
88
9+ // Version is set on build by the Git release tag.
10+ var version string
11+
912func main () {
13+ command .CommandVersion = version
1014 _ , err := flags .Parse (& command .Command )
1115 if err != nil {
1216 if flagsErr , ok := err .(* flags.Error ); ok && flagsErr .Type == flags .ErrHelp {
You can’t perform that action at this time.
0 commit comments