From aa3a70d6843cf8ddafd4a5bff771f9c515283f4e Mon Sep 17 00:00:00 2001 From: Kenshi Muto Date: Sun, 5 Nov 2023 12:35:12 +0900 Subject: [PATCH] pass version --- .goreleaser.yaml | 2 ++ checkmackerelmetric/checkmackerelmetric.go | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index a7e46dc..d8def86 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -16,6 +16,8 @@ builds: - arm64 ldflags: - -s -w + - -X main.version={{ .Version }} + - -X main.revision={{ .ShortCommit }} archives: - format: zip diff --git a/checkmackerelmetric/checkmackerelmetric.go b/checkmackerelmetric/checkmackerelmetric.go index 93e523b..3bb60c8 100644 --- a/checkmackerelmetric/checkmackerelmetric.go +++ b/checkmackerelmetric/checkmackerelmetric.go @@ -21,6 +21,13 @@ type mackerelMetricOpts struct { Critical uint `arg:"-c,--critical,required" help:"minute to be CRITICAL (MINUTE: 1-1441)" placeholder:"MINUTE"` } +var version string +var revision string + +func (mackerelMetricOpts) Version() string { + return fmt.Sprintf("Version %s (rev.%s)", version, revision) +} + func Do() { opts, err := parseArgs(os.Args[1:]) if err != nil {