mirror of
https://github.com/onyx-and-iris/xair-cli.git
synced 2026-02-03 23:17:47 +00:00
lint fixes
This commit is contained in:
parent
d1657e09ab
commit
d823aeeb8e
@ -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
|
||||
|
||||
11
cmd/main.go
11
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",
|
||||
|
||||
15
cmd/root.go
15
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 {
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user