From 22903f7af571b45339b1ccd3c64f6d41ad0740a3 Mon Sep 17 00:00:00 2001 From: Ryan McKern <344926+mckern@users.noreply.github.com> Date: Fri, 19 Jan 2024 16:51:52 -0800 Subject: [PATCH] Fix version formatting (#118) Hardcoded version numbers are easy to forget to update. --- .goreleaser.yaml | 2 -- main.go | 17 ++++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 1c3fbd6..8817565 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -5,8 +5,6 @@ before: builds: - main: . - ldflags: - - -s -w flags: - -trimpath - -v diff --git a/main.go b/main.go index f505a72..1e5fd6c 100644 --- a/main.go +++ b/main.go @@ -15,11 +15,13 @@ import ( kingpin "gopkg.in/alecthomas/kingpin.v2" ) -const ( - versionStr = "0.11.0" -) - var ( + // these values are provided automatically by Goreleaser + // ref: https://goreleaser.com/customization/builds/ + version = "dev" + commit = "none" + date = "unknown" + // Flags baseFormatterCmd = kingpin.Flag( "base-formatter", @@ -64,7 +66,7 @@ var ( tabLen = kingpin.Flag( "tab-len", "Length of a tab").Short('t').Default("4").Int() - version = kingpin.Flag( + versionFlag = kingpin.Flag( "version", "Print out version and exit").Default("false").Bool() writeOutput = kingpin.Flag( @@ -86,8 +88,9 @@ func main() { log.SetLevel(log.InfoLevel) } - if *version { - fmt.Printf("golines v%s\n", versionStr) + if *versionFlag { + fmt.Printf("golines v%s\n\nbuild information:\n\tbuild date: %s\n\tgit commit ref: %s\n", + version, date, commit) return }