Add version subcommand and Makefile semver bump targets

- var version injected at build time via -X main.version=$(VERSION)
- VERSION derives from 'git describe --tags' so built binaries show
  the exact tag (or tag+commits+sha for dirty/untagged builds)
- 'make patch/minor/major' reads the latest vX.Y.Z tag and creates
  the next one; starts from v0.0.0 if no tags exist yet
This commit is contained in:
2026-03-25 15:55:17 +11:00
parent e18fa8e4f3
commit 7d256a999f
2 changed files with 33 additions and 2 deletions
+10
View File
@@ -25,6 +25,8 @@ const (
appName = "node-lookup"
)
var version = "dev"
// config holds all configurable values. Fields map 1:1 to config file keys,
// env vars (NODE_LOOKUP_*), and (where applicable) CLI flags.
type config struct {
@@ -397,6 +399,14 @@ func main() {
configCmd.AddCommand(configInitCmd, configShowCmd)
rootCmd.AddCommand(configCmd)
versionCmd := &cobra.Command{
Use: "version",
Short: "Print the version",
Run: func(cmd *cobra.Command, args []string) { fmt.Println(version) },
SilenceUsage: true,
}
rootCmd.AddCommand(versionCmd)
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}