mirror of
https://github.com/RGBCube/superfreq
synced 2025-07-27 08:57:46 +00:00
core: validate tresholds at the CLI level
This commit is contained in:
parent
90fd077a67
commit
6fe322272e
3 changed files with 30 additions and 10 deletions
|
@ -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<String>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[derive(Deserialize, Serialize, Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum LogLevel {
|
||||
Error,
|
||||
Warning,
|
||||
|
|
|
@ -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
|
||||
|
|
20
src/main.rs
20
src/main.rs
|
@ -370,12 +370,32 @@ fn main() {
|
|||
start_threshold,
|
||||
stop_threshold,
|
||||
}) => {
|
||||
// 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<dyn std::error::Error>)
|
||||
} 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<dyn std::error::Error>)
|
||||
} 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<dyn std::error::Error>)
|
||||
} 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<dyn std::error::Error>)
|
||||
}
|
||||
}
|
||||
Some(Commands::Daemon { verbose }) => daemon::run_daemon(config, verbose),
|
||||
Some(Commands::Debug) => cli::debug::run_debug(&config),
|
||||
None => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue