enable.go 930 B

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