package main import ( "encoding/json" "fmt" "os" "github.com/spf13/cobra" "github.com/wobkey/rgb/cmd/wobkey/rgb" "github.com/wobkey/rgb/internal/device" ) var rootCmd = &cobra.Command{ Use: "wobkey", Short: "Wobkey RGB CLI — control VIA-compatible keyboard lighting", } func Execute() { if err := rootCmd.Execute(); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } } func main() { Execute() } var keyboardCmd = &cobra.Command{ Use: "keyboard", Short: "Keyboard management commands", } var keyboardInfoCmd = &cobra.Command{ Use: "info", Short: "Discover connected VIA-compatible keyboards", Long: "Scan for connected VIA-compatible keyboards and print device info as JSON.", Run: func(cmd *cobra.Command, args []string) { keyboards, err := device.LoadKeyboards() if err != nil { fmt.Fprintf(os.Stderr, "Error: %v\n", err) os.Exit(1) } devices, err := device.Discover(keyboards) if err != nil { fmt.Fprintf(os.Stderr, "Error: %v\n", err) os.Exit(1) } if len(devices) == 0 { fmt.Println(`{"devices":[]}`) return } type Info struct { Devices []device.Device `json:"devices"` Total int `json:"total"` } out := Info{Devices: devices, Total: len(devices)} data, _ := json.MarshalIndent(out, "", " ") fmt.Println(string(data)) }, } func init() { rootCmd.AddCommand(keyboardCmd) keyboardCmd.AddCommand(keyboardInfoCmd) rgbCmd := rgb.Init() rgbCmd.AddCommand( rgb.NewEffectCmd(), rgb.NewBrightnessCmd(), rgb.NewSpeedCmd(), rgb.NewColorCmd(), rgb.NewModeCmd(), rgb.NewEnableCmd(), rgb.NewDisableCmd(), rgb.NewInfoCmd(), ) rootCmd.AddCommand(rgbCmd) }