mirror of
https://github.com/onyx-and-iris/xair-cli.git
synced 2026-04-09 02:13:35 +00:00
add persistent flag --kind
use it to configure the client
This commit is contained in:
@@ -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
|
||||
|
||||
11
cmd/root.go
11
cmd/root.go
@@ -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"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user