enable.go 919 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package main
  2. import (
  3. "fmt"
  4. "github.com/spf13/cobra"
  5. intrgb "netdome.biz/paul/qmk-rgb/internal/rgb"
  6. )
  7. func NewEnableCmd() *cobra.Command {
  8. return &cobra.Command{
  9. Use: "enable",
  10. Short: "Enable RGB lighting",
  11. Args: cobra.NoArgs,
  12. RunE: func(cmd *cobra.Command, args []string) error {
  13. proto, target, channels, err := openTarget()
  14. if err != nil {
  15. return err
  16. }
  17. defer proto.Close()
  18. catalog, _ := intrgb.CatalogFor(target.Device.VendorID, target.Device.ProductID)
  19. for _, ch := range channels {
  20. if _, ok := catalog.DefaultEffect(ch); !ok {
  21. return fmt.Errorf("this keyboard has no effect catalog, so `enable` cannot choose an effect; set one with `mode <index>`")
  22. }
  23. }
  24. if err := enableLightingOnChannels(proto, channels, catalog); err != nil {
  25. return fmt.Errorf("enable RGB: %w", err)
  26. }
  27. fmt.Fprintln(cmd.OutOrStdout(), "RGB enabled")
  28. return nil
  29. },
  30. }
  31. }