From d823aeeb8ea6b944e0c0c4955a01143894c740ed Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Sat, 31 Jan 2026 19:33:04 +0000 Subject: [PATCH] lint fixes --- cmd/context.go | 5 ++--- cmd/main.go | 11 ++++++----- cmd/root.go | 15 +++++++-------- cmd/util.go | 5 ++--- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/cmd/context.go b/cmd/context.go index d7be5a8..3614b78 100644 --- a/cmd/context.go +++ b/cmd/context.go @@ -1,6 +1,3 @@ -/* -LICENSE: https://github.com/onyx-and-iris/xair-cli/blob/main/LICENSE -*/ package cmd import ( @@ -11,10 +8,12 @@ import ( type clientKey string +// WithContext returns a new context with the provided xair.Client. func WithContext(ctx context.Context, client *xair.Client) context.Context { return context.WithValue(ctx, clientKey("oscClient"), client) } +// ClientFromContext retrieves the xair.Client from the context. func ClientFromContext(ctx context.Context) *xair.Client { if client, ok := ctx.Value(clientKey("oscClient")).(*xair.Client); ok { return client diff --git a/cmd/main.go b/cmd/main.go index 6236993..e3313fe 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -1,6 +1,3 @@ -/* -LICENSE: https://github.com/onyx-and-iris/xair-cli/blob/main/LICENSE -*/ package cmd import ( @@ -9,16 +6,17 @@ import ( "github.com/spf13/cobra" ) -// mainCmd represents the main command +// mainCmd represents the main command. var mainCmd = &cobra.Command{ Use: "main", Short: "Commands to control the main output", Long: `Commands to control the main output of the XAir mixer, including fader level and mute status.`, - Run: func(cmd *cobra.Command, args []string) { + Run: func(cmd *cobra.Command, _ []string) { cmd.Help() }, } +// mainMuteCmd represents the main mute command. var mainMuteCmd = &cobra.Command{ Use: "mute", Short: "Get or set the main LR mute status", @@ -69,6 +67,7 @@ For example: }, } +// mainFaderCmd represents the main fader command. var mainFaderCmd = &cobra.Command{ Use: "fader", Short: "Set or get the main LR fader level", @@ -110,6 +109,7 @@ For example: }, } +// mainFadeOutCmd represents the main fadeout command. var mainFadeOutCmd = &cobra.Command{ Use: "fadeout [target_db]", Short: "Fade out the main output", @@ -169,6 +169,7 @@ This command will fade out the main output to the specified dB level. }, } +// mainFadeInCmd represents the main fadein command. var mainFadeInCmd = &cobra.Command{ Use: "fadein [target_db]", Short: "Fade in the main output", diff --git a/cmd/root.go b/cmd/root.go index 4b62e27..43461f4 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,6 +1,3 @@ -/* -LICENSE: https://github.com/onyx-and-iris/xair-cli/blob/main/LICENSE -*/ package cmd import ( @@ -14,14 +11,14 @@ import ( "github.com/onyx-and-iris/xair-cli/internal/xair" ) -// rootCmd represents the base command when called without any subcommands +// rootCmd represents the base command when called without any subcommands. var rootCmd = &cobra.Command{ Use: "xair-cli", Short: "A command-line utility to interact with Behringer X Air mixers via OSC", 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.`, - PersistentPreRunE: func(cmd *cobra.Command, args []string) error { + PersistentPreRunE: func(cmd *cobra.Command, _ []string) error { level, err := log.ParseLevel(viper.GetString("loglevel")) if err != nil { return err @@ -29,7 +26,7 @@ various commands to manage mixer settings directly from the terminal.`, log.SetLevel(level) kind := viper.GetString("kind") - log.Debugf("Initializing client for mixer kind: %s", kind) + log.Debugf("Initialising client for mixer kind: %s", kind) if kind == "x32" && !viper.IsSet("port") { viper.Set("port", 10023) @@ -55,18 +52,20 @@ various commands to manage mixer settings directly from the terminal.`, return nil }, - PersistentPostRunE: func(cmd *cobra.Command, args []string) error { + PersistentPostRunE: func(cmd *cobra.Command, _ []string) error { client := ClientFromContext(cmd.Context()) if client != nil { client.Stop() } return nil }, - Run: func(cmd *cobra.Command, args []string) { + Run: func(cmd *cobra.Command, _ []string) { cmd.Help() }, } +// Execute adds all child commands to the root command and sets flags appropriately. +// This is called by main.main(). It only needs to happen once to the rootCmd. func Execute() { err := rootCmd.Execute() if err != nil { diff --git a/cmd/util.go b/cmd/util.go index b7d8f63..41cf9d9 100644 --- a/cmd/util.go +++ b/cmd/util.go @@ -1,12 +1,10 @@ -/* -LICENSE: https://github.com/onyx-and-iris/xair-cli/blob/main/LICENSE -*/ package cmd import ( "strconv" ) +// mustConvToFloat64 converts a string to float64, panicking on error. func mustConvToFloat64(floatStr string) float64 { level, err := strconv.ParseFloat(floatStr, 64) if err != nil { @@ -15,6 +13,7 @@ func mustConvToFloat64(floatStr string) float64 { return level } +// mustConvToInt converts a string to int, panicking on error. func mustConvToInt(intStr string) int { val, err := strconv.Atoi(intStr) if err != nil {