Skip to content

Commit 22903f7

Browse files
authored
Fix version formatting (#118)
Hardcoded version numbers are easy to forget to update.
1 parent fe1c9ae commit 22903f7

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

.goreleaser.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ before:
55

66
builds:
77
- main: .
8-
ldflags:
9-
- -s -w
108
flags:
119
- -trimpath
1210
- -v

main.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ import (
1515
kingpin "gopkg.in/alecthomas/kingpin.v2"
1616
)
1717

18-
const (
19-
versionStr = "0.11.0"
20-
)
21-
2218
var (
19+
// these values are provided automatically by Goreleaser
20+
// ref: https://goreleaser.com/customization/builds/
21+
version = "dev"
22+
commit = "none"
23+
date = "unknown"
24+
2325
// Flags
2426
baseFormatterCmd = kingpin.Flag(
2527
"base-formatter",
@@ -64,7 +66,7 @@ var (
6466
tabLen = kingpin.Flag(
6567
"tab-len",
6668
"Length of a tab").Short('t').Default("4").Int()
67-
version = kingpin.Flag(
69+
versionFlag = kingpin.Flag(
6870
"version",
6971
"Print out version and exit").Default("false").Bool()
7072
writeOutput = kingpin.Flag(
@@ -86,8 +88,9 @@ func main() {
8688
log.SetLevel(log.InfoLevel)
8789
}
8890

89-
if *version {
90-
fmt.Printf("golines v%s\n", versionStr)
91+
if *versionFlag {
92+
fmt.Printf("golines v%s\n\nbuild information:\n\tbuild date: %s\n\tgit commit ref: %s\n",
93+
version, date, commit)
9194
return
9295
}
9396

0 commit comments

Comments
 (0)