lint fixes

This commit is contained in:
onyx-and-iris 2026-01-31 19:33:04 +00:00
parent d1657e09ab
commit d823aeeb8e
4 changed files with 17 additions and 19 deletions

View File

@ -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

View File

@ -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",

View File

@ -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 {

View File

@ -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 {