From 77640d1637c046335f382acdb4377adfa4d5a8a6 Mon Sep 17 00:00:00 2001 From: Denis Benato Date: Wed, 14 Jan 2026 01:05:35 +0100 Subject: [PATCH] feat: improve profile cli usage --- asusctl/src/cli_opts.rs | 55 +++++++++++++++++++++++++++++--------- asusctl/src/main.rs | 59 ++++++++++++++++++----------------------- 2 files changed, 68 insertions(+), 46 deletions(-) diff --git a/asusctl/src/cli_opts.rs b/asusctl/src/cli_opts.rs index 559863ab..281dc6a9 100644 --- a/asusctl/src/cli_opts.rs +++ b/asusctl/src/cli_opts.rs @@ -49,34 +49,63 @@ pub enum CliCommand { Info(InfoCommand), } -#[derive(FromArgs, Debug, Clone, Default)] +#[derive(FromArgs, Debug)] #[argh(subcommand, name = "profile", description = "profile management")] pub struct ProfileCommand { - #[argh(switch, description = "toggle to next profile in list")] - pub next: bool, + #[argh(subcommand)] + pub command: ProfileSubCommand, +} - #[argh(switch, description = "list available profiles")] - pub list: bool, +#[derive(FromArgs, Debug)] +#[argh(subcommand)] +pub enum ProfileSubCommand { + Next(ProfileNextCommand), + List(ProfileListCommand), + Get(ProfileGetCommand), + Set(ProfileSetCommand), +} - #[argh(switch, description = "get profile")] - pub profile_get: bool, +impl Default for ProfileSubCommand { + fn default() -> Self { + ProfileSubCommand::List(ProfileListCommand::default()) + } +} - #[argh(option, description = "set the active profile")] - pub profile_set: Option, +#[derive(FromArgs, Debug, Default)] +#[argh( + subcommand, + name = "next", + description = "toggle to next profile in list" +)] +pub struct ProfileNextCommand {} + +#[derive(FromArgs, Debug, Default)] +#[argh(subcommand, name = "list", description = "list available profiles")] +pub struct ProfileListCommand {} + +#[derive(FromArgs, Debug, Default)] +#[argh(subcommand, name = "get", description = "get profile")] +pub struct ProfileGetCommand {} + +#[derive(FromArgs, Debug, Default)] +#[argh(subcommand, name = "set", description = "set profile")] +pub struct ProfileSetCommand { + #[argh(positional, description = "profile to set")] + pub profile: PlatformProfile, #[argh( - option, + switch, short = 'a', description = "set the profile to use on AC power" )] - pub profile_set_ac: Option, + pub ac: bool, #[argh( - option, + switch, short = 'b', description = "set the profile to use on battery power" )] - pub profile_set_bat: Option, + pub battery: bool, } #[derive(FromArgs, Debug, Default)] diff --git a/asusctl/src/main.rs b/asusctl/src/main.rs index dad20baa..baa6ab44 100644 --- a/asusctl/src/main.rs +++ b/asusctl/src/main.rs @@ -816,44 +816,37 @@ fn handle_throttle_profile( return Err(ProfileError::NotSupported.into()); } - if !cmd.next - && !cmd.list - && cmd.profile_set.is_none() - && !cmd.profile_get - && cmd.profile_set_ac.is_none() - && cmd.profile_set_bat.is_none() - { - println!("Missing arg or command; run 'asusctl profile --help' for usage"); - return Ok(()); - } - let proxy = PlatformProxyBlocking::new(conn)?; let current = proxy.platform_profile()?; let choices = proxy.platform_profile_choices()?; - if cmd.next { - proxy.set_platform_profile(PlatformProfile::next(current, &choices))?; - } else if let Some(profile) = cmd.profile_set { - proxy.set_platform_profile(profile)?; - } else if let Some(profile) = cmd.profile_set_ac { - proxy.set_platform_profile_on_ac(profile)?; - } else if let Some(profile) = cmd.profile_set_bat { - proxy.set_platform_profile_on_battery(profile)?; - } - - if cmd.list { - for p in &choices { - println!("{:?}", p); + match &cmd.command { + crate::cli_opts::ProfileSubCommand::Next(_) => { + proxy.set_platform_profile(PlatformProfile::next(current, &choices))?; + } + crate::cli_opts::ProfileSubCommand::Set(s) => { + if !s.ac && !s.battery { + proxy.set_platform_profile(s.profile)?; + } else { + if s.ac { + proxy.set_platform_profile_on_ac(s.profile)?; + } + if s.battery { + proxy.set_platform_profile_on_battery(s.profile)?; + } + } + } + crate::cli_opts::ProfileSubCommand::List(_) => { + for p in &choices { + println!("{:?}", p); + } + } + crate::cli_opts::ProfileSubCommand::Get(_) => { + println!("Active profile: {current:?}"); + println!(""); + println!("AC profile {:?}", proxy.platform_profile_on_ac()?); + println!("Battery profile {:?}", proxy.platform_profile_on_battery()?); } - } - - if cmd.profile_get { - println!("Active profile is {current:?}"); - println!("Profile on AC is {:?}", proxy.platform_profile_on_ac()?); - println!( - "Profile on Battery is {:?}", - proxy.platform_profile_on_battery()? - ); } Ok(())