| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package main
- import (
- "fmt"
- "github.com/spf13/cobra"
- )
- func NewModeCmd() *cobra.Command {
- return &cobra.Command{
- Use: "mode <index>",
- Short: "Set effect mode by index",
- Long: "Set the effect mode by numeric index (0-255). The index is the\n" +
- "channel's own: 5 is light on rgblight and rainbow_beacon on rgb_matrix.\n" +
- "Use `effect <name>` where a catalog exists, which is unambiguous.\n" +
- "The index is read back, because a board that does not implement it\n" +
- "clamps it to the highest it does instead of refusing it.",
- Args: cobra.ExactArgs(1),
- RunE: func(cmd *cobra.Command, args []string) error {
- val, err := ParseUint8(args[0])
- if err != nil {
- return err
- }
- proto, target, channels, err := openTarget()
- if err != nil {
- return err
- }
- defer proto.Close()
- results, err := setModeVerified(proto, channels, target.Display, val)
- if err != nil {
- return fmt.Errorf("set mode: %w", err)
- }
- // Claiming an index the keyboard clamped away is the same
- // contradiction the other verified sets avoid.
- if anyMismatch(results) {
- fmt.Fprintln(cmd.OutOrStdout(), formatResults("Mode", results))
- return nil
- }
- fmt.Fprintf(cmd.OutOrStdout(), "Mode set to index %d\n", val)
- return nil
- },
- }
- }
|