From 9010cdccde441d37aff8a1d76f2e701134e42801 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Thu, 15 Oct 2020 20:02:19 -0700 Subject: Add support for -version argument This will help determine the version of the binary particularly on Cloud Native GitLab, where VERSION may not be shipped with the binaries. --- cmd/gitlab-shell/main.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'cmd/gitlab-shell') 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, -- cgit v1.2.1