diff --git a/cmd/root.go b/cmd/root.go index e5ecf85..42d8e7d 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -16,7 +16,15 @@ var rootCmd = &cobra.Command{ Switch between different git identities (work, personal, school, etc.) with a single command. Profiles are stored in ~/.config/git-context/config.yaml`, - Version: "1.0.0", + Version: "dev", +} + +// SetVersion overrides the version reported by `git-context --version`. +// Called from main with the value goreleaser injects via ldflag. +func SetVersion(v string) { + if v != "" { + rootCmd.Version = v + } } var initCmd = &cobra.Command{ diff --git a/main.go b/main.go index dd8df1c..b7d72a8 100644 --- a/main.go +++ b/main.go @@ -7,7 +7,14 @@ import ( "github.com/aanogueira/git-context/cmd" ) +// version is set at build time via goreleaser's +// `-X main.version={{.Version}}` ldflag. Defaults to "dev" for local +// `go build` / `go install` invocations. +var version = "dev" + func main() { + cmd.SetVersion(version) + if err := cmd.Execute(); err != nil { fmt.Fprintf(os.Stderr, "Error: %v\n", err) os.Exit(1)