| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- package rgb
- import (
- "fmt"
- "os"
- "github.com/spf13/cobra"
- "github.com/wobkey/rgb/internal/rgb"
- )
- func NewColorCmd() *cobra.Command {
- return &cobra.Command{
- Use: "color <hex>",
- 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.SetLightingColor(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])
- },
- }
- }
|