Skip to content

Commit d1b2a13

Browse files
committed
feat: Add --version flag with build-time version injection
Set Cobra's Version field on root command with ldflags support. GoReleaser config updated to inject git tag version at build time.
1 parent 6544a32 commit d1b2a13

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

.goreleaser.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ builds:
2020
- linux
2121
- windows
2222
- darwin
23+
ldflags:
24+
- -s -w -X github.com/Pairadux/muxly/cmd.Version={{.Version}}
2325

2426
archives:
2527
- formats: [tar.gz]

cmd/root.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,13 @@ var (
2828
verbose bool
2929
)
3030

31+
// Version is set at build time via ldflags
32+
var Version = "dev"
33+
3134
// rootCmd represents the base command when called without any subcommands
3235
var rootCmd = &cobra.Command{
3336
Use: "muxly [SESSION]",
37+
Version: Version,
3438
Example: "",
3539
Short: "A tool for quickly opening tmux sessions",
3640
Long: "A tool for quickly opening tmux sessions\n\nBased on ThePrimeagen's tmux-sessionizer script.",

0 commit comments

Comments
 (0)