From 4c4d52c74ef5e0350235d6e56c6c427b2cc0202a Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Sat, 31 Jan 2026 23:13:09 +0000 Subject: [PATCH] add --version flag --- cmd/root.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cmd/root.go b/cmd/root.go index 43461f4..4f78739 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -2,6 +2,7 @@ package cmd import ( "os" + "runtime/debug" "strings" "github.com/charmbracelet/log" @@ -11,6 +12,8 @@ import ( "github.com/onyx-and-iris/xair-cli/internal/xair" ) +var version string // Version of the CLI, set during build time + // rootCmd represents the base command when called without any subcommands. var rootCmd = &cobra.Command{ Use: "xair-cli", @@ -18,6 +21,7 @@ var rootCmd = &cobra.Command{ Long: `xair-cli is a command-line tool that allows users to send OSC messages to Behringer X Air mixers for remote control and configuration. It supports various commands to manage mixer settings directly from the terminal.`, + Version: versionFromBuild(), PersistentPreRunE: func(cmd *cobra.Command, _ []string) error { level, err := log.ParseLevel(viper.GetString("loglevel")) if err != nil { @@ -88,3 +92,15 @@ func init() { viper.BindPFlag("loglevel", rootCmd.PersistentFlags().Lookup("loglevel")) viper.BindPFlag("kind", rootCmd.PersistentFlags().Lookup("kind")) } + +func versionFromBuild() string { + if version == "" { + info, ok := debug.ReadBuildInfo() + if !ok { + return "(unable to read version)" + } + version = strings.Split(info.Main.Version, "-")[0] + } + + return version +}