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:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user