Skip to content

Commit dbc93dc

Browse files
authored
Merge pull request #19 from techquestsdev/andre.nogueira/version-from-ldflag
fix(version): plumb goreleaser ldflag into --version
2 parents 49d844b + 965f815 commit dbc93dc

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

cmd/root.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@ var rootCmd = &cobra.Command{
1616
1717
Switch between different git identities (work, personal, school, etc.) with a single command.
1818
Profiles are stored in ~/.config/git-context/config.yaml`,
19-
Version: "1.0.0",
19+
Version: "dev",
20+
}
21+
22+
// SetVersion overrides the version reported by `git-context --version`.
23+
// Called from main with the value goreleaser injects via ldflag.
24+
func SetVersion(v string) {
25+
if v != "" {
26+
rootCmd.Version = v
27+
}
2028
}
2129

2230
var initCmd = &cobra.Command{

main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ import (
77
"github.com/aanogueira/git-context/cmd"
88
)
99

10+
// version is set at build time via goreleaser's
11+
// `-X main.version={{.Version}}` ldflag. Defaults to "dev" for local
12+
// `go build` / `go install` invocations.
13+
var version = "dev"
14+
1015
func main() {
16+
cmd.SetVersion(version)
17+
1118
if err := cmd.Execute(); err != nil {
1219
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
1320
os.Exit(1)

0 commit comments

Comments
 (0)