From 87f8c5f2ec2062f5224f39d1f7fdd069c571b70f Mon Sep 17 00:00:00 2001 From: Chris Marslender Date: Fri, 8 Mar 2024 23:01:56 -0600 Subject: [PATCH] Add --version flag (#145) --- Makefile | 2 +- cmd/root.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 2af269e..b98ab8c 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ all: fmt lint vet build .PHONY: build build: $(BIN) ; $(info $(M) building executable…) @ ## Build program binary $Q CGO_ENABLED=0 $(GO) build \ - -ldflags "-X main.gitVersion=$$(git describe --tags) -X \"main.buildTime=$$(date -u '+%Y-%m-%d %H:%M:%S %Z')\"" \ + -ldflags "-X main.gitVersion=$$(git describe --tags) -X $(MODULE)/cmd.gitVersion=$$(git describe --tags) -X \"main.buildTime=$$(date -u '+%Y-%m-%d %H:%M:%S %Z')\" -X \"$(MODULE)/cmd.buildTime=$$(date -u '+%Y-%m-%d %H:%M:%S %Z')\"" \ -tags release \ -o $(BIN)/$(notdir $(basename $(MODULE)))$(binext) # Tools diff --git a/cmd/root.go b/cmd/root.go index a5ce992..b4a9e33 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -11,11 +11,16 @@ import ( ) var cfgFile string +var ( + gitVersion string + buildTime string +) // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ Use: "chia-exporter", Short: "Prometheus metric exporter for Chia Blockchain", + Version: fmt.Sprintf("%s (%s)", gitVersion, buildTime), } // Execute adds all child commands to the root command and sets flags appropriately.