speed.go 990 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package main
  2. import (
  3. "fmt"
  4. "github.com/spf13/cobra"
  5. )
  6. func NewSpeedCmd() *cobra.Command {
  7. return withZoneArgs(&cobra.Command{
  8. Use: "speed <zone> <val>",
  9. Short: "Set effect speed on a zone",
  10. Long: writesLighting("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. RunE: func(cmd *cobra.Command, args []string) error {
  13. val, err := ParseUint8(args[1])
  14. if err != nil {
  15. return err
  16. }
  17. proto, target, channels, err := openTarget(args[0])
  18. if err != nil {
  19. return err
  20. }
  21. defer proto.Close()
  22. results, err := setSpeedVerified(proto, channels, target.Display, val)
  23. if err != nil {
  24. return fmt.Errorf("set speed: %w", err)
  25. }
  26. if anyMismatch(results) {
  27. fmt.Fprintln(cmd.OutOrStdout(), formatResults("Speed", results))
  28. return nil
  29. }
  30. fmt.Fprintf(cmd.OutOrStdout(), "Speed set to %d\n", val)
  31. return nil
  32. },
  33. }, 2, 2, "a zone and a speed value")
  34. }