use std::process::exit;
use batno::{BatteryMonitor, monitor_battery, print_battery_info};
use clap::Parser;
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
pub struct Args {
#[arg(short, long, default_value_t = 30)]
monitor_interval: u32,
#[arg(short, long, default_value_t = 20)]
notify_threshold: u8,
#[arg(short, long, default_value_t = 25)]
reset_threshold: u8,
#[arg(short, long, default_value_t = false)]
battery_info: bool,
}
fn main() {
let args = Args::parse();
if args.reset_threshold <= args.notify_threshold {
eprintln!("reset-threshold must be greater than notify-threshold.");
exit(1)
}
let monitor = BatteryMonitor::new_linux(
args.notify_threshold,
args.reset_threshold,
args.monitor_interval,
)
.unwrap_or_else(|e| {
eprintln!("{e}");
exit(1);
});
if args.battery_info {
print_battery_info(&monitor);
return;
}
monitor_battery(monitor);
}