mirror of
https://github.com/onyx-and-iris/xair-cli.git
synced 2026-02-04 07:27: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
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -11,10 +8,12 @@ import (
|
|||||||
|
|
||||||
type clientKey string
|
type clientKey string
|
||||||
|
|
||||||
|
// WithContext returns a new context with the provided xair.Client.
|
||||||
func WithContext(ctx context.Context, client *xair.Client) context.Context {
|
func WithContext(ctx context.Context, client *xair.Client) context.Context {
|
||||||
return context.WithValue(ctx, clientKey("oscClient"), client)
|
return context.WithValue(ctx, clientKey("oscClient"), client)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClientFromContext retrieves the xair.Client from the context.
|
||||||
func ClientFromContext(ctx context.Context) *xair.Client {
|
func ClientFromContext(ctx context.Context) *xair.Client {
|
||||||
if client, ok := ctx.Value(clientKey("oscClient")).(*xair.Client); ok {
|
if client, ok := ctx.Value(clientKey("oscClient")).(*xair.Client); ok {
|
||||||
return client
|
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
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -9,16 +6,17 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
// mainCmd represents the main command
|
// mainCmd represents the main command.
|
||||||
var mainCmd = &cobra.Command{
|
var mainCmd = &cobra.Command{
|
||||||
Use: "main",
|
Use: "main",
|
||||||
Short: "Commands to control the main output",
|
Short: "Commands to control the main output",
|
||||||
Long: `Commands to control the main output of the XAir mixer, including fader level and mute status.`,
|
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()
|
cmd.Help()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// mainMuteCmd represents the main mute command.
|
||||||
var mainMuteCmd = &cobra.Command{
|
var mainMuteCmd = &cobra.Command{
|
||||||
Use: "mute",
|
Use: "mute",
|
||||||
Short: "Get or set the main LR mute status",
|
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{
|
var mainFaderCmd = &cobra.Command{
|
||||||
Use: "fader",
|
Use: "fader",
|
||||||
Short: "Set or get the main LR fader level",
|
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{
|
var mainFadeOutCmd = &cobra.Command{
|
||||||
Use: "fadeout [target_db]",
|
Use: "fadeout [target_db]",
|
||||||
Short: "Fade out the main output",
|
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{
|
var mainFadeInCmd = &cobra.Command{
|
||||||
Use: "fadein [target_db]",
|
Use: "fadein [target_db]",
|
||||||
Short: "Fade in the main output",
|
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
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -14,14 +11,14 @@ import (
|
|||||||
"github.com/onyx-and-iris/xair-cli/internal/xair"
|
"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{
|
var rootCmd = &cobra.Command{
|
||||||
Use: "xair-cli",
|
Use: "xair-cli",
|
||||||
Short: "A command-line utility to interact with Behringer X Air mixers via OSC",
|
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
|
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.`,
|
||||||
PersistentPreRunE: func(cmd *cobra.Command, args []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 {
|
||||||
return err
|
return err
|
||||||
@ -29,7 +26,7 @@ various commands to manage mixer settings directly from the terminal.`,
|
|||||||
log.SetLevel(level)
|
log.SetLevel(level)
|
||||||
|
|
||||||
kind := viper.GetString("kind")
|
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") {
|
if kind == "x32" && !viper.IsSet("port") {
|
||||||
viper.Set("port", 10023)
|
viper.Set("port", 10023)
|
||||||
@ -55,18 +52,20 @@ various commands to manage mixer settings directly from the terminal.`,
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
PersistentPostRunE: func(cmd *cobra.Command, args []string) error {
|
PersistentPostRunE: func(cmd *cobra.Command, _ []string) error {
|
||||||
client := ClientFromContext(cmd.Context())
|
client := ClientFromContext(cmd.Context())
|
||||||
if client != nil {
|
if client != nil {
|
||||||
client.Stop()
|
client.Stop()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, _ []string) {
|
||||||
cmd.Help()
|
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() {
|
func Execute() {
|
||||||
err := rootCmd.Execute()
|
err := rootCmd.Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -1,12 +1,10 @@
|
|||||||
/*
|
|
||||||
LICENSE: https://github.com/onyx-and-iris/xair-cli/blob/main/LICENSE
|
|
||||||
*/
|
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// mustConvToFloat64 converts a string to float64, panicking on error.
|
||||||
func mustConvToFloat64(floatStr string) float64 {
|
func mustConvToFloat64(floatStr string) float64 {
|
||||||
level, err := strconv.ParseFloat(floatStr, 64)
|
level, err := strconv.ParseFloat(floatStr, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -15,6 +13,7 @@ func mustConvToFloat64(floatStr string) float64 {
|
|||||||
return level
|
return level
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// mustConvToInt converts a string to int, panicking on error.
|
||||||
func mustConvToInt(intStr string) int {
|
func mustConvToInt(intStr string) int {
|
||||||
val, err := strconv.Atoi(intStr)
|
val, err := strconv.Atoi(intStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user