Commit 965f815
committed
fix(version): plumb goreleaser ldflag into cobra Version
The cobra root command had `Version: "1.0.0"` hardcoded, so
`git-context --version` always reported 1.0.0 regardless of which
release was installed. .goreleaser.yml already injects the right
value via `-X main.version={{.Version}}`, but main.go had no
matching `version` variable for the ldflag to land in, and even if
it did, cmd/root.go wouldn't see it.
Declare `var version = "dev"` in main.go so the ldflag has a target,
expose `cmd.SetVersion` to overwrite the cobra Version field at
startup, and call it from main(). Local `go install` / `go build`
without ldflags continues to report "dev"; goreleaser builds report
the real tag.
Signed-off-by: Andre Nogueira <aanogueira@protonmail.com>1 parent 49d844b commit 965f815
2 files changed
Lines changed: 16 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
20 | 28 | | |
21 | 29 | | |
22 | 30 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
10 | 15 | | |
| 16 | + | |
| 17 | + | |
11 | 18 | | |
12 | 19 | | |
13 | 20 | | |
| |||
0 commit comments