mirror of
https://github.com/onyx-and-iris/xair-cli.git
synced 2026-02-04 07:27:47 +00:00
add --version flag
This commit is contained in:
parent
7536c4fe24
commit
4c4d52c74e
16
cmd/root.go
16
cmd/root.go
@ -2,6 +2,7 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"runtime/debug"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/charmbracelet/log"
|
"github.com/charmbracelet/log"
|
||||||
@ -11,6 +12,8 @@ import (
|
|||||||
"github.com/onyx-and-iris/xair-cli/internal/xair"
|
"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.
|
// rootCmd represents the base command when called without any subcommands.
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
Use: "xair-cli",
|
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
|
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
|
to Behringer X Air mixers for remote control and configuration. It supports
|
||||||
various commands to manage mixer settings directly from the terminal.`,
|
various commands to manage mixer settings directly from the terminal.`,
|
||||||
|
Version: versionFromBuild(),
|
||||||
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
|
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
|
||||||
level, err := log.ParseLevel(viper.GetString("loglevel"))
|
level, err := log.ParseLevel(viper.GetString("loglevel"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -88,3 +92,15 @@ func init() {
|
|||||||
viper.BindPFlag("loglevel", rootCmd.PersistentFlags().Lookup("loglevel"))
|
viper.BindPFlag("loglevel", rootCmd.PersistentFlags().Lookup("loglevel"))
|
||||||
viper.BindPFlag("kind", rootCmd.PersistentFlags().Lookup("kind"))
|
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
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user