From 174a64501d1e36c88a24a8fa488b1caaa713bbee Mon Sep 17 00:00:00 2001 From: Jamie Wilkinson Date: Wed, 28 Jun 2017 15:02:30 +0200 Subject: [PATCH] Print build info in the --help output. --- Makefile | 2 +- main.go | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 08015ce31..69ca94680 100644 --- a/Makefile +++ b/Makefile @@ -68,7 +68,7 @@ version := $(shell git describe --tags) revision := $(shell git rev-parse HEAD) install mtail: $(GOFILES) .dep-stamp - go install -ldflags "-X main.version=${version} -X main.revision=${revision}" + go install -ldflags "-X main.Version=${version} -X main.Revision=${revision}" vm/parser.go: vm/parser.y .gen-dep-stamp go generate -x ./vm diff --git a/main.go b/main.go index ce56b2091..10ca401db 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,8 @@ package main import ( "flag" + "fmt" + "os" "runtime" "strconv" "strings" @@ -34,12 +36,22 @@ var ( var ( // Externally supplied by the linker Version string + Revision string GoVersion = runtime.Version() ) +func buildInfo() string { + return fmt.Sprintf("mtail version %s git revision %s go version %s", Version, Revision, GoVersion) +} + func main() { - glog.Infof("Mtail version %s go version %s", Version, GoVersion) + flag.Usage = func() { + fmt.Fprintf(os.Stderr, "%s\n", buildInfo()) + fmt.Fprintf(os.Stderr, "\nUsage:\n") + flag.PrintDefaults() + } flag.Parse() + glog.Info(buildInfo()) if *progs == "" { glog.Exitf("No mtail program directory specified; use -progs") }