Skip to content

Commit

Permalink
Fix version formatting (#118)
Browse files Browse the repository at this point in the history
Hardcoded version numbers are easy to forget to update.
  • Loading branch information
mckern authored Jan 20, 2024
1 parent fe1c9ae commit 22903f7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
2 changes: 0 additions & 2 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ before:

builds:
- main: .
ldflags:
- -s -w
flags:
- -trimpath
- -v
Expand Down
17 changes: 10 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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(
Expand All @@ -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
}

Expand Down

0 comments on commit 22903f7

Please sign in to comment.