add persistent flag --kind

use it to configure the client
This commit is contained in:
2026-01-31 01:29:14 +00:00
parent ddbf52430a
commit d5c88f31e0
6 changed files with 52 additions and 22 deletions

View File

@@ -11,12 +11,12 @@ import (
type clientKey string
func WithContext(ctx context.Context, client *xair.XAirClient) context.Context {
func WithContext(ctx context.Context, client *xair.Client) context.Context {
return context.WithValue(ctx, clientKey("oscClient"), client)
}
func ClientFromContext(ctx context.Context) *xair.XAirClient {
if client, ok := ctx.Value(clientKey("oscClient")).(*xair.XAirClient); ok {
func ClientFromContext(ctx context.Context) *xair.Client {
if client, ok := ctx.Value(clientKey("oscClient")).(*xair.Client); ok {
return client
}
return nil

View File

@@ -28,7 +28,14 @@ various commands to manage mixer settings directly from the terminal.`,
}
log.SetLevel(level)
client, err := xair.NewClient(viper.GetString("host"), viper.GetInt("port"))
kind := xair.NewMixerKind(viper.GetString("kind"))
log.Debugf("Initializing client for mixer kind: %s", kind)
client, err := xair.NewClient(
viper.GetString("host"),
viper.GetInt("port"),
xair.WithKind(string(kind)),
)
if err != nil {
return err
}
@@ -68,6 +75,7 @@ func init() {
rootCmd.PersistentFlags().IntP("port", "p", 10024, "Port number of the X Air mixer")
rootCmd.PersistentFlags().
StringP("loglevel", "l", "warn", "Log level (debug, info, warn, error, fatal, panic)")
rootCmd.PersistentFlags().StringP("kind", "k", "xair", "Kind of mixer (xair, x32)")
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
viper.SetEnvPrefix("XAIR_CLI")
@@ -75,4 +83,5 @@ func init() {
viper.BindPFlag("host", rootCmd.PersistentFlags().Lookup("host"))
viper.BindPFlag("port", rootCmd.PersistentFlags().Lookup("port"))
viper.BindPFlag("loglevel", rootCmd.PersistentFlags().Lookup("loglevel"))
viper.BindPFlag("kind", rootCmd.PersistentFlags().Lookup("kind"))
}