package main import ( "fmt" "github.com/spf13/cobra" ) func NewBrightnessCmd() *cobra.Command { return withZoneArgs(&cobra.Command{ Use: "brightness ", Short: "Set RGB brightness on a zone", Long: writesLighting("Set the RGB brightness value (0-255) and read it back, so a value the\n" + "keyboard clamps or rescales is reported instead of silently applied."), RunE: func(cmd *cobra.Command, args []string) error { val, err := ParseUint8(args[1]) if err != nil { return err } proto, target, channels, err := openTarget(args[0]) if err != nil { return err } defer proto.Close() results, err := setBrightnessVerified(proto, channels, target.Display, val) if err != nil { return fmt.Errorf("set brightness: %w", err) } // Claiming "set to N" when the keyboard holds something else is // the contradiction this read-back exists to prevent. if anyMismatch(results) { fmt.Fprintln(cmd.OutOrStdout(), formatResults("Brightness", results)) return nil } fmt.Fprintf(cmd.OutOrStdout(), "Brightness set to %d\n", val) return nil }, }, 2, 2, "a zone and a brightness value") }