mode.go 881 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package main
  2. import (
  3. "fmt"
  4. "github.com/spf13/cobra"
  5. )
  6. func NewModeCmd() *cobra.Command {
  7. return &cobra.Command{
  8. Use: "mode <index>",
  9. Short: "Set effect mode by index",
  10. Long: "Set the effect mode by numeric index (0-255). The index is the\n" +
  11. "channel's own: 5 is light on rgblight and rainbow_beacon on rgb_matrix.\n" +
  12. "Use `effect <name>` where a catalog exists, which is unambiguous.",
  13. Args: cobra.ExactArgs(1),
  14. RunE: func(cmd *cobra.Command, args []string) error {
  15. val, err := ParseUint8(args[0])
  16. if err != nil {
  17. return err
  18. }
  19. proto, _, channels, err := openTarget()
  20. if err != nil {
  21. return err
  22. }
  23. defer proto.Close()
  24. if err := setModeOnChannels(proto, channels, val); err != nil {
  25. return fmt.Errorf("set mode: %w", err)
  26. }
  27. fmt.Fprintf(cmd.OutOrStdout(), "Mode set to index %d\n", val)
  28. return nil
  29. },
  30. }
  31. }