fix: reject out-of-range led brightness instead of silently clamping

led accepted any u16 and main.rs clamped to 0..=1000 with no feedback,
inconsistent with sidetone which rejects out-of-range at parse time.
Add a clap range validator (0..=1000) and drop the silent clamp, so
invalid input now fails loudly.

Further quality-audit follow-ups:
- remove dead BragiDevice::open() (no caller; binary uses open_with_verbose)
- add tests: led range validation, format_battery for all status
  variants, waybar "unknown" class

Bump 0.1.2 -> 0.1.3.
This commit is contained in:
2026-06-10 17:51:40 +02:00
parent e364f4edec
commit baada36222
7 changed files with 49 additions and 10 deletions
+1 -5
View File
@@ -22,11 +22,7 @@ pub struct BragiDevice {
impl BragiDevice {
/// Findet ein Corsair-Gerät, öffnet es und führt die Init-Sequenz durch.
pub fn open() -> Result<Self> {
Self::open_with_verbose(false)
}
/// Wie `open()`, aber mit optionalem Debug-Output auf stderr.
/// Mit optionalem Debug-Output auf stderr.
pub fn open_with_verbose(verbose: bool) -> Result<Self> {
let api = HidApi::new()?;
if verbose {
+1
View File
@@ -29,6 +29,7 @@ pub enum Command {
/// LED-Helligkeit lesen oder setzen (0-1000)
Led {
/// Helligkeit (0-1000). Ohne Angabe wird der aktuelle Wert gelesen.
#[arg(value_parser = clap::value_parser!(u16).range(0..=1000))]
brightness: Option<u16>,
},
+2 -3
View File
@@ -33,9 +33,8 @@ fn run() -> error::Result<()> {
Command::Led { brightness } => {
let device = bragi::BragiDevice::open_with_verbose(cli.verbose)?;
if let Some(value) = brightness {
let clamped = value.clamp(0, 1000);
device.set_brightness(clamped)?;
println!("{}", output::format_brightness(clamped));
device.set_brightness(value)?;
println!("{}", output::format_brightness(value));
} else {
let current = device.brightness()?;
println!("{}", output::format_brightness(current));