refactor(src/commands): enhance battery command error handling and readability

Restructure loops, add explicit error handling, improve multi‑line messages, and fix formatting issues.

- Enhancements
  - Use explicit braces for error branches to prevent silent failures
  - Wrap warning and informational messages in multi‑line `println!` with consistent spacing
  - Refactor directory reads for Ideapad fallback to avoid nested `let` bindings
  - Improve parsing and formatting of AMD TDP limit output with clear parentheses
  - Provide clearer debug logging when writing to threshold files
- Bug Fixes
  - Added missing braces around error handling to ensure proper execution flow
  - Fixed variable binding scope for `ideapad_entries` to prevent shadowing
  - Ensured consistent handling of missing `charge_control_end_threshold` across all entries

no changes.
This commit is contained in:
sankalp committed 2026-03-12 00:27:37 +05:45
1 parent 47aa4613d6
commit 8bd5b52b05
7 files changed
+242 -80

No files matched your search

+1 -5
View File
@@ -1,5 +1,4 @@
use crate::cli::CoolingCommands;
use crate::utils::system::assert_root;
use log::{debug, info};
use std::fs;
use std::path::Path;
@@ -38,10 +37,7 @@ fn set_asus_throttle_policy(mode: &str) -> bool {
success
}
pub fn execute(command: &CoolingCommands) {
assert_root();
let (ideapad_mode, asus_mode, desc) = match command {
CoolingCommands::Performance => ("1", "1", "Performance"),
CoolingCommands::Balanced => ("0", "0", "Balanced"),
@@ -55,7 +51,7 @@ pub fn execute(command: &CoolingCommands) {
applied = true;
println!("Ideapad fan mode applied.");
}
if set_asus_throttle_policy(asus_mode) {
applied = true;
println!("ASUS thermal policy applied.");