From eab21bb2b1c93dd1d9aaae3b1c56c228f4daf089 Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Wed, 11 Mar 2026 23:32:15 +0545 Subject: [PATCH] feat(src): Introduce full CLI interface for laptop hardware management MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add clap‑based CLI with subcommands (gpu, battery, power, status), verbose flag, and detailed options such as rtd3, use_nvidia_current, etc. - New Features - New CLI entry point with complete subcommand hierarchy - Verbose logging support - Granular command options for GPU, Battery, Power, Status - Enhancements - Replace placeholder hello world with proper logging initialization - Modularize command implementations into dedicated modules --- src/cli.rs | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 30 +++++++++++++++- 2 files changed, 131 insertions(+), 1 deletion(-) diff --git a/src/cli.rs b/src/cli.rs index e69de29..eb17529 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -0,0 +1,102 @@ +use clap::{Parser, Subcommand}; + +#[derive(Parser, Debug)] +#[command( + name = "lapctl", + version, + about = "CLI utility for managing laptop hardware features on Linux." +)] +pub struct Cli { + #[command(subcommand)] + pub command: Commands, + + /// Enable verbose logging + #[arg(short, long, global = true)] + pub verbose: bool, +} + +#[derive(Subcommand, Debug)] +pub enum Commands { + /// GPU management commands + Gpu { + #[command(subcommand)] + command: GpuCommands, + }, + /// Battery management commands + Battery { + #[command(subcommand)] + command: BatteryCommands, + }, + /// Power management commands + Power { + #[command(subcommand)] + command: PowerCommands, + }, + /// Hardware status + Status, +} + +#[derive(Subcommand, Debug)] +pub enum GpuCommands { + /// Query the current graphics mode + Query, + /// Switch to integrated graphics + Integrated, + /// Switch to hybrid graphics + Hybrid { + /// Setup PCI-Express Runtime D3 (RTD3) Power Management on Hybrid mode (0, 1, 2, 3) + #[arg(long)] + rtd3: Option, + /// Use nvidia-current instead of nvidia for kernel modules + #[arg(long)] + use_nvidia_current: bool, + }, + /// Switch to NVIDIA graphics + Nvidia { + /// Manually specify your Display Manager (gdm, sddm, lightdm) + #[arg(long)] + dm: Option, + /// Enable ForceCompositionPipeline on Nvidia mode + #[arg(long)] + force_comp: bool, + /// Enable Coolbits on Nvidia mode + #[arg(long)] + coolbits: Option, + /// Use nvidia-current instead of nvidia for kernel modules + #[arg(long)] + use_nvidia_current: bool, + /// Set up Nvidia mode for Wayland (skips Xorg configuration) + #[arg(long)] + wayland: bool, + }, + /// Revert changes made by lapctl + Reset, + /// Restore default sddm Xsetup file + ResetSddm, + /// Create cache used by lapctl (hybrid mode only) + CacheCreate, + /// Delete cache created by lapctl + CacheDelete, + /// Show cache created by lapctl + CacheQuery, +} + +#[derive(Subcommand, Debug)] +pub enum PowerCommands { + /// Set power profile to performance + Performance, + /// Set power profile to balanced + Balanced, + /// Set power profile to battery saver + BatterySave, +} + +#[derive(Subcommand, Debug)] +pub enum BatteryCommands { + /// Set the battery charging limit (e.g., 80) + Limit { + percent: u8, + }, + /// Show current battery status + Status, +} diff --git a/src/main.rs b/src/main.rs index e7a11a9..122e9e7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,31 @@ +use clap::Parser; + +mod cli; +mod commands; +mod hardware; +mod utils; + +use cli::{Cli, Commands}; + fn main() { - println!("Hello, world!"); + let cli = Cli::parse(); + + let level = if cli.verbose { + log::LevelFilter::Debug + } else { + log::LevelFilter::Info + }; + + env_logger::Builder::new() + .filter_level(level) + .format_timestamp(None) + .format_module_path(false) + .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::Status => commands::status::execute(), + } }