Files
lapctl/src/main.rs
T
sankalp 74aa1ff262 fix(src): handle tokio runtime creation errors gracefullyBug Fixes:
- Added proper error handling for tokio runtime creation, exiting with a clear error message instead of panicking.
2026-05-25 14:50:06 +05:45

50 lines
1.6 KiB
Rust

use clap::Parser;
use lapctl::cli::{Cli, Commands};
use lapctl::commands;
fn main() {
let cli = Cli::parse();
let level = if cli.verbose {
log::LevelFilter::Debug
} else {
log::LevelFilter::Info
};
use std::io::Write;
env_logger::Builder::new()
.filter_level(level)
.format(|buf, record| {
// Write only [LEVEL] message
writeln!(buf, "[{}] {}", record.level(), record.args())
})
.init();
match &cli.command {
Commands::Gpu { command } => commands::gpu::execute(command),
Commands::Battery { command } => commands::battery::execute(command),
Commands::Power { command } => commands::power::execute(command),
Commands::Cooling { command } => commands::cooling::execute(command),
Commands::Display { command } => commands::display::execute(command),
Commands::Status => commands::status::execute(),
Commands::InstallRules => commands::install_rules::execute(),
Commands::Touchpad { command } => commands::touchpad::execute(command),
Commands::Daemon => {
let rt = match tokio::runtime::Runtime::new() {
Ok(rt) => rt,
Err(e) => {
eprintln!("Failed to create tokio runtime: {}", e);
std::process::exit(1);
}
};
rt.block_on(async {
if let Err(e) = lapctl::daemon::run().await {
eprintln!("Daemon error: {}", e);
std::process::exit(1);
}
});
}
}
}