diff --git a/src/config/types.rs b/src/config/types.rs index 988170f..500320f 100644 --- a/src/config/types.rs +++ b/src/config/types.rs @@ -154,7 +154,7 @@ impl Default for ProfileConfigToml { } } -#[derive(Deserialize, Debug, Clone)] +#[derive(Deserialize, Serialize, Debug, Clone)] pub struct TurboAutoSettings { #[serde(default = "default_load_threshold_high")] pub load_threshold_high: f32, @@ -230,7 +230,7 @@ pub struct DaemonConfig { pub stats_file_path: Option, } -#[derive(Deserialize, Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Deserialize, Serialize, Debug, Clone, Copy, PartialEq, Eq)] pub enum LogLevel { Error, Warning, @@ -261,7 +261,7 @@ const fn default_adaptive_interval() -> bool { } const fn default_min_poll_interval_sec() -> u64 { - 1 + 1 } const fn default_max_poll_interval_sec() -> u64 { diff --git a/src/core.rs b/src/core.rs index 2be64ff..76dc940 100644 --- a/src/core.rs +++ b/src/core.rs @@ -1,8 +1,8 @@ use clap::ValueEnum; -use serde::Deserialize; +use serde::{Deserialize, Serialize}; use std::fmt; -#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, ValueEnum)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize, ValueEnum)] pub enum TurboSetting { Always, // turbo is forced on (if possible) Auto, // system or driver controls turbo diff --git a/src/main.rs b/src/main.rs index dc9bf6a..3755929 100644 --- a/src/main.rs +++ b/src/main.rs @@ -370,11 +370,31 @@ fn main() { start_threshold, stop_threshold, }) => { - info!( - "Setting battery thresholds: start at {start_threshold}%, stop at {stop_threshold}%" - ); - battery::set_battery_charge_thresholds(start_threshold, stop_threshold) - .map_err(|e| Box::new(e) as Box) + // Basic validation to provide proper error messages at the CLI level + if start_threshold >= stop_threshold { + error!( + "Start threshold ({start_threshold}) must be less than stop threshold ({stop_threshold})" + ); + Err(Box::new(ControlError::InvalidValueError(format!( + "Start threshold ({start_threshold}) must be less than stop threshold ({stop_threshold})" + ))) as Box) + } else if stop_threshold > 100 { + error!("Stop threshold ({stop_threshold}) cannot exceed 100%"); + Err(Box::new(ControlError::InvalidValueError(format!( + "Stop threshold ({stop_threshold}) cannot exceed 100%" + ))) as Box) + } else if start_threshold == 0 || stop_threshold == 0 { + error!("Thresholds must be greater than 0%"); + Err(Box::new(ControlError::InvalidValueError( + "Thresholds must be greater than 0%".to_string(), + )) as Box) + } else { + info!( + "Setting battery thresholds: start at {start_threshold}%, stop at {stop_threshold}%" + ); + battery::set_battery_charge_thresholds(start_threshold, stop_threshold) + .map_err(|e| Box::new(e) as Box) + } } Some(Commands::Daemon { verbose }) => daemon::run_daemon(config, verbose), Some(Commands::Debug) => cli::debug::run_debug(&config),