refactor: inject version from main at build time

Amolith created

Moves version declaration to main.go with a default of "dev", allowing
build-time injection via ldflags while keeping cmd.Execute() pure.

Assisted-by: Claude Opus 4.5 via Crush <crush@charm.land>

Change summary

cmd/root.go | 3 ++-
main.go     | 4 +++-
2 files changed, 5 insertions(+), 2 deletions(-)

Detailed changes

cmd/root.go 🔗

@@ -75,7 +75,8 @@ func init() {
 }
 
 // Execute runs the root command with Fang styling.
-func Execute(ctx context.Context) error {
+func Execute(ctx context.Context, v string) error {
+	version = v
 	return fang.Execute(
 		ctx,
 		rootCmd,

main.go 🔗

@@ -12,8 +12,10 @@ import (
 	"git.secluded.site/lune/cmd"
 )
 
+var version = "dev"
+
 func main() {
-	if err := cmd.Execute(context.Background()); err != nil {
+	if err := cmd.Execute(context.Background(), version); err != nil {
 		os.Exit(1)
 	}
 }