Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

Commit 1445678

Browse files
committed
Display go version in commands
1 parent bd9765c commit 1445678

File tree

8 files changed

+31
-20
lines changed

8 files changed

+31
-20
lines changed

.goreleaser.yml

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ project_name: datautils
22
builds:
33
- binary: norm
44
main: ./cmd/norm/main.go
5+
ldflags: -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.goVersion={{.Env.GOVERSION}}
56
env:
67
- CGO_ENABLED=0
78
goos:
@@ -12,6 +13,7 @@ builds:
1213
- amd64
1314
- binary: count
1415
main: ./cmd/count/main.go
16+
ldflags: -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.goVersion={{.Env.GOVERSION}}
1517
env:
1618
- CGO_ENABLED=0
1719
goos:
@@ -22,6 +24,7 @@ builds:
2224
- amd64
2325
- binary: rows
2426
main: ./cmd/rows/main.go
27+
ldflags: -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.goVersion={{.Env.GOVERSION}}
2528
env:
2629
- CGO_ENABLED=0
2730
goos:
@@ -32,6 +35,7 @@ builds:
3235
- amd64
3336
- binary: text
3437
main: ./cmd/text/main.go
38+
ldflags: -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.goVersion={{.Env.GOVERSION}}
3539
env:
3640
- CGO_ENABLED=0
3741
goos:
@@ -42,6 +46,7 @@ builds:
4246
- amd64
4347
- binary: trim
4448
main: ./cmd/trim/main.go
49+
ldflags: -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.goVersion={{.Env.GOVERSION}}
4550
env:
4651
- CGO_ENABLED=0
4752
goos:

Makefile

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CMDS = count norm rows text trim
55

66
# metadata
77
DATE = $(shell date -I)
8+
GOVERSION = $(shell go version | awk '{print $$3}')
89

910
# commands
1011
MK = mkdir -p
@@ -22,17 +23,17 @@ GZS = $(addsuffix .gz, $(MNS))
2223
all: show clean man
2324

2425
build:
25-
goreleaser --rm-dist
26+
GOVERSION=$(GOVERSION) goreleaser --rm-dist
2627

2728
buildclean:
2829
$(RM) dist/
2930
@echo
3031

3132
buildsnapshot:
32-
goreleaser --snapshot --rm-dist
33+
GOVERSION=$(GOVERSION) goreleaser --snapshot --rm-dist
3334

3435
buildtestsnapshot:
35-
goreleaser --snapshot --rm-dist --skip-publish
36+
GOVERSION=$(GOVERSION) goreleaser --snapshot --rm-dist --skip-publish
3637

3738
checks: checktest checkmeta checkbats
3839

cmd/count/main.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ import (
1414
)
1515

1616
var (
17-
version = "v?.?.?"
18-
date = "????-??-??"
17+
date = "????-??-??"
18+
goVersion = "go?.?.?"
19+
version = "v?.?.?"
1920
)
2021

2122
func main() {
22-
app := datautils.DefaultApp(version, date)
23+
app := datautils.DefaultApp(version, date, goVersion)
2324
app.Name = "count"
2425
app.Usage = "count lines from text files"
2526

cmd/norm/main.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ import (
1313
)
1414

1515
var (
16-
version = "v?.?.?"
17-
date = "????-??-??"
16+
date = "????-??-??"
17+
goVersion = "go?.?.?"
18+
version = "v?.?.?"
1819
)
1920

2021
func main() {
21-
app := datautils.DefaultApp(version, date)
22+
app := datautils.DefaultApp(version, date, goVersion)
2223
app.Name = "norm"
2324
app.Usage = "normalize text files into Unicode normal forms"
2425

cmd/rows/main.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ import (
1212
)
1313

1414
var (
15-
version = "v?.?.?"
16-
date = "????-??-??"
15+
date = "????-??-??"
16+
goVersion = "go?.?.?"
17+
version = "v?.?.?"
1718
)
1819

1920
func main() {
20-
app := datautils.DefaultApp(version, date)
21+
app := datautils.DefaultApp(version, date, goVersion)
2122
app.Name = "rows"
2223
app.Usage = "select lines from text files"
2324

cmd/text/main.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ import (
1313
)
1414

1515
var (
16-
version = "v?.?.?"
17-
date = "????-??-??"
16+
date = "????-??-??"
17+
goVersion = "go?.?.?"
18+
version = "v?.?.?"
1819
)
1920

2021
func main() {
21-
app := datautils.DefaultApp(version, date)
22+
app := datautils.DefaultApp(version, date, goVersion)
2223
app.Name = "text"
2324
app.Usage = "manipulate content from text files"
2425

cmd/trim/main.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ import (
1414
)
1515

1616
var (
17-
version = "v?.?.?"
18-
date = "????-??-??"
17+
date = "????-??-??"
18+
goVersion = "go?.?.?"
19+
version = "v?.?.?"
1920
)
2021

2122
func main() {
22-
app := datautils.DefaultApp(version, date)
23+
app := datautils.DefaultApp(version, date, goVersion)
2324
app.Name = "trim"
2425
app.Usage = "remove white space from text files"
2526

main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ func processStdin(c *cli.Context, process func(string) error) error {
2626
return err
2727
}
2828

29-
func DefaultApp(version, date string) *cli.App {
29+
func DefaultApp(version, date, goVersion string) *cli.App {
3030
app := cli.NewApp()
3131
dateTime := ParseRFCDate(date).Format("2006-01-02")
32-
app.Version = fmt.Sprintf("%s (%s)", version, dateTime)
32+
app.Version = fmt.Sprintf("%s (%s, %s)", version, dateTime, goVersion)
3333
app.Copyright = "Copyright (c) 2017 Stefan Fischer"
3434
app.Author = "Stefan Fischer"
3535
app.Email = "sfischer13@ymail.com"

0 commit comments

Comments
 (0)