| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package main
- import (
- "fmt"
- "github.com/spf13/cobra"
- )
- func NewSpeedCmd() *cobra.Command {
- return &cobra.Command{
- Use: "speed <val>",
- Short: "Set effect speed",
- Long: "Set the effect speed (0-255) and read it back, so a value the keyboard\n" +
- "rescales is reported instead of silently applied.",
- Args: cobra.ExactArgs(1),
- RunE: func(cmd *cobra.Command, args []string) error {
- val, err := ParseUint8(args[0])
- if err != nil {
- return err
- }
- zones, err := selectedZones()
- if err != nil {
- return err
- }
- proto, err := openRGBProtocol()
- if err != nil {
- return err
- }
- defer proto.Close()
- results, err := setSpeedVerified(proto, zones, val)
- if err != nil {
- return fmt.Errorf("set speed: %w", err)
- }
- if anyMismatch(results) {
- fmt.Fprintln(cmd.OutOrStdout(), formatResults("Speed", results))
- return nil
- }
- fmt.Fprintf(cmd.OutOrStdout(), "Speed set to %d\n", val)
- return nil
- },
- }
- }
|