mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-01-22 17:33:19 +01:00
feat: improve profile cli usage
This commit is contained in:
@@ -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<PlatformProfile>,
|
||||
#[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<PlatformProfile>,
|
||||
pub ac: bool,
|
||||
|
||||
#[argh(
|
||||
option,
|
||||
switch,
|
||||
short = 'b',
|
||||
description = "set the profile to use on battery power"
|
||||
)]
|
||||
pub profile_set_bat: Option<PlatformProfile>,
|
||||
pub battery: bool,
|
||||
}
|
||||
|
||||
#[derive(FromArgs, Debug, Default)]
|
||||
|
||||
@@ -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 {
|
||||
match &cmd.command {
|
||||
crate::cli_opts::ProfileSubCommand::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 {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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()?
|
||||
);
|
||||
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()?);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user