speed.go 930 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package main
  2. import (
  3. "fmt"
  4. "github.com/spf13/cobra"
  5. )
  6. func NewSpeedCmd() *cobra.Command {
  7. return &cobra.Command{
  8. Use: "speed <val>",
  9. Short: "Set effect speed",
  10. Long: "Set the effect speed (0-255) and read it back, so a value the keyboard\n" +
  11. "rescales is reported instead of silently applied.",
  12. Args: cobra.ExactArgs(1),
  13. RunE: func(cmd *cobra.Command, args []string) error {
  14. val, err := ParseUint8(args[0])
  15. if err != nil {
  16. return err
  17. }
  18. proto, target, channels, err := openTarget()
  19. if err != nil {
  20. return err
  21. }
  22. defer proto.Close()
  23. results, err := setSpeedVerified(proto, channels, target.Display, val)
  24. if err != nil {
  25. return fmt.Errorf("set speed: %w", err)
  26. }
  27. if anyMismatch(results) {
  28. fmt.Fprintln(cmd.OutOrStdout(), formatResults("Speed", results))
  29. return nil
  30. }
  31. fmt.Fprintf(cmd.OutOrStdout(), "Speed set to %d\n", val)
  32. return nil
  33. },
  34. }
  35. }