diff options
author | Ash McKenzie <amckenzie@gitlab.com> | 2020-10-16 06:27:48 +0000 |
---|---|---|
committer | Ash McKenzie <amckenzie@gitlab.com> | 2020-10-16 06:27:48 +0000 |
commit | 6da1094b190a76231ec6d4ee4f0a0846de916446 (patch) | |
tree | d9df0ab3dfa832f195fa55e1ccc73486615f54cc | |
parent | 890bda90c9a09aa8d5a2441974138b92c8e38c18 (diff) | |
parent | 89a23f1923aa122734e92ddb588f20694959afbf (diff) | |
download | gitlab-shell-6da1094b190a76231ec6d4ee4f0a0846de916446.tar.gz |
Merge branch 'sh-add-version-arg' into 'master'
Add support for -version argument
See merge request gitlab-org/gitlab-shell!421
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | cmd/gitlab-shell/main.go | 14 |
2 files changed, 18 insertions, 1 deletions
@@ -1,6 +1,9 @@ .PHONY: validate verify verify_ruby verify_golang test test_ruby test_golang coverage coverage_golang setup _install build compile check clean GO_SOURCES := $(shell find . -name '*.go') +VERSION_STRING := $(shell git describe --match v* 2>/dev/null || awk '$0="v"$0' VERSION 2>/dev/null || echo unknown) +BUILD_TIME := $(shell date -u +%Y%m%d.%H%M%S) +GOBUILD_FLAGS := -ldflags "-X main.Version=$(VERSION_STRING) -X main.BuildTime=$(BUILD_TIME)" validate: verify test @@ -37,7 +40,7 @@ _install: build: bin/gitlab-shell compile: bin/gitlab-shell bin/gitlab-shell: $(GO_SOURCES) - GOBIN="$(CURDIR)/bin" go install ./cmd/... + GOBIN="$(CURDIR)/bin" go install $(GOBUILD_FLAGS) ./cmd/... check: bin/check diff --git a/cmd/gitlab-shell/main.go b/cmd/gitlab-shell/main.go index 763aa5e..ff3a354 100644 --- a/cmd/gitlab-shell/main.go +++ b/cmd/gitlab-shell/main.go @@ -12,7 +12,21 @@ import ( "gitlab.com/gitlab-org/gitlab-shell/internal/logger" ) +var ( + // Version is the current version of gitlab-shell + Version = "(unknown version)" // Set at build time in the Makefile + // BuildTime signifies the time the binary was build + BuildTime = "19700101.000000" // Set at build time in the Makefile +) + func main() { + // We can't use the flag library because gitlab-shell receives other arguments + // that confuse the parser. + if len(os.Args) == 2 && os.Args[1] == "-version" { + fmt.Printf("gitlab-shell %s-%s\n", Version, BuildTime) + os.Exit(0) + } + readWriter := &readwriter.ReadWriter{ Out: os.Stdout, In: os.Stdin, |