Skip to content

Commit c21ee60

Browse files
author
Doug Hatcher
committed
adds a version command
1 parent 33baa6b commit c21ee60

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Diff for: Makefile

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@ ifeq (run,$(firstword $(MAKECMDGOALS)))
55
$(eval $(RUN_ARGS):;@:)
66
endif
77

8+
VERSION := $(shell git tag | grep ^v | sort -V | tail -n 1)
9+
LDFLAGS = -ldflags "-X main.Version=${VERSION}"
10+
811
.PHONY: help
912

1013
help:
1114
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
1215

1316
build: ## creates binary
14-
go build .
17+
go build ${LDFLAGS} .
1518
install: build ## compiles and installs into system
1619
sudo cp magento-cli /usr/local/bin/magento
1720
sudo chmod +x /usr/local/bin/magento
1821
run: ## run the command through go, accepts args i.e. `make run -- build -h`
19-
go run ./main.go $(RUN_ARGS)
22+
go run ${LDFLAGS} ./main.go $(RUN_ARGS)
2023
test: build
2124
go test --cover ./...
2225
coverage: build ## run test suite suitable for codecov.io

Diff for: main.go

+12
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,19 @@ var testMode = false
3535

3636
var tempDir string = "./" + configDir + "/tmp"
3737

38+
var Version string = ""
39+
3840
func main() {
41+
42+
// output version info
43+
if len(os.Args) > 1 {
44+
arg := os.Args[1]
45+
if arg == "version" {
46+
fmt.Println("Magento CLI by Blue Acorn iCi x Infosys " + Version)
47+
os.Exit(0)
48+
}
49+
}
50+
3951
// put services files in a temp directory
4052
extractYamlToTemp(services)
4153

0 commit comments

Comments
 (0)