enable.go 1.1 KB

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