From 4e607bd7a5584d833da02101daf08d738c5413b7 Mon Sep 17 00:00:00 2001 From: clarabennett2626 Date: Sun, 15 Feb 2026 14:55:24 -0500 Subject: [PATCH] feat: add --version flag Add --version flag support using cobra's built-in version functionality. Version and build date are injected via ldflags at build time (already configured in .goreleaser.yaml), with sensible defaults for dev builds. Closes #52 --- cmd/root.go | 6 ++++++ main.go | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/cmd/root.go b/cmd/root.go index 304a673..ac2238a 100755 --- a/cmd/root.go +++ b/cmd/root.go @@ -81,6 +81,12 @@ var rootCmd = &cobra.Command{ }, } +// SetVersionInfo sets the version information for the root command. +func SetVersionInfo(version, buildDate string) { + rootCmd.Version = version + rootCmd.SetVersionTemplate(fmt.Sprintf("nomore403 version %s (built %s)\n", version, buildDate)) +} + // Execute adds all child commands to the root command and sets flags appropriately. // This is called by main.main(). It only needs to happen once to the rootCmd. func Execute() { diff --git a/main.go b/main.go index ad0003a..767fe9c 100755 --- a/main.go +++ b/main.go @@ -4,6 +4,13 @@ package main import "github.com/devploit/nomore403/cmd" +// Version and BuildDate are set via ldflags at build time. +var ( + Version = "dev" + BuildDate = "unknown" +) + func main() { + cmd.SetVersionInfo(Version, BuildDate) cmd.Execute() }