package rgb import ( "fmt" "os" "github.com/spf13/cobra" "github.com/wobkey/rgb/internal/rgb" "github.com/wobkey/rgb/internal/via" ) func NewColorCmd() *cobra.Command { return &cobra.Command{ Use: "color ", Short: "Set RGB color", Long: "Set the RGB color using a 6-digit hex code (e.g. \"ff0000\" for red).", Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { c, err := rgb.ParseHexColor(args[0]) if err != nil { fmt.Fprintf(os.Stderr, "Error: %v\n", err) os.Exit(1) } proto, _, err := OpenDevice() if err != nil { fmt.Fprintf(os.Stderr, "Error: %v\n", err) os.Exit(1) } defer proto.Close() h, s, _ := c.HSV() if err := proto.SetColor(via.RGBLight, h, s); err != nil { fmt.Fprintf(os.Stderr, "Error setting color: %v\n", err) os.Exit(1) } fmt.Printf("Color set to %s\n", args[0]) }, } }