From 219d9ed59210c61781591695b821cd47192dac6f Mon Sep 17 00:00:00 2001 From: Michael van Tricht Date: Tue, 8 Nov 2016 14:28:15 +0100 Subject: [PATCH] Add version flag which displays the current version. --- Makefile | 2 +- main.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f16456a..c0252fd 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ combined: go install . release: tag release-deps dockerhub - gox -output="build/{{.Dir}}_{{.OS}}_{{.Arch}}" . + gox -ldflags "-X main.version=${VERSION}" -output="build/{{.Dir}}_{{.OS}}_{{.Arch}}" . fmt: go fmt ./... diff --git a/main.go b/main.go index df52832..5e92f24 100644 --- a/main.go +++ b/main.go @@ -25,6 +25,7 @@ var apiconf *cfgapi.Config var uiconf *cfgui.Config var comconf *cfgcom.Config var exitCh chan int +var version string func configure() { cfgcom.RegisterFlags() @@ -40,6 +41,11 @@ func configure() { } func main() { + if len(os.Args) > 1 && (os.Args[1] == "-version" || os.Args[1] == "--version") { + fmt.Println("MailHog version: " + version) + os.Exit(0) + } + if len(os.Args) > 1 && os.Args[1] == "sendmail" { args := os.Args os.Args = []string{args[0]}