From 3b81414591c0483ee6ddbd18b471ad1ad8564267 Mon Sep 17 00:00:00 2001 From: Amolith Date: Tue, 23 Dec 2025 13:45:48 -0700 Subject: [PATCH] refactor: inject version from main at build time 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 --- cmd/root.go | 3 ++- main.go | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 19368cadd4f38c7fa65dd95b2c60c5dcbbcfe2c1..408a3584e28114927db43a9b76e7e90d2710a487 100644 --- a/cmd/root.go +++ b/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, diff --git a/main.go b/main.go index ef157be97882f220d3b038707dc80971b5d3d20e..a2ba566aeddd0d36baa6c7fab2ca3c9549848f53 100644 --- a/main.go +++ b/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) } }