mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-01-22 09:23:19 +01:00
feat: improve profile cli usage
This commit is contained in:
@@ -49,34 +49,63 @@ pub enum CliCommand {
|
|||||||
Info(InfoCommand),
|
Info(InfoCommand),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(FromArgs, Debug, Clone, Default)]
|
#[derive(FromArgs, Debug)]
|
||||||
#[argh(subcommand, name = "profile", description = "profile management")]
|
#[argh(subcommand, name = "profile", description = "profile management")]
|
||||||
pub struct ProfileCommand {
|
pub struct ProfileCommand {
|
||||||
#[argh(switch, description = "toggle to next profile in list")]
|
#[argh(subcommand)]
|
||||||
pub next: bool,
|
pub command: ProfileSubCommand,
|
||||||
|
}
|
||||||
|
|
||||||
#[argh(switch, description = "list available profiles")]
|
#[derive(FromArgs, Debug)]
|
||||||
pub list: bool,
|
#[argh(subcommand)]
|
||||||
|
pub enum ProfileSubCommand {
|
||||||
|
Next(ProfileNextCommand),
|
||||||
|
List(ProfileListCommand),
|
||||||
|
Get(ProfileGetCommand),
|
||||||
|
Set(ProfileSetCommand),
|
||||||
|
}
|
||||||
|
|
||||||
#[argh(switch, description = "get profile")]
|
impl Default for ProfileSubCommand {
|
||||||
pub profile_get: bool,
|
fn default() -> Self {
|
||||||
|
ProfileSubCommand::List(ProfileListCommand::default())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[argh(option, description = "set the active profile")]
|
#[derive(FromArgs, Debug, Default)]
|
||||||
pub profile_set: Option<PlatformProfile>,
|
#[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(
|
#[argh(
|
||||||
option,
|
switch,
|
||||||
short = 'a',
|
short = 'a',
|
||||||
description = "set the profile to use on AC power"
|
description = "set the profile to use on AC power"
|
||||||
)]
|
)]
|
||||||
pub profile_set_ac: Option<PlatformProfile>,
|
pub ac: bool,
|
||||||
|
|
||||||
#[argh(
|
#[argh(
|
||||||
option,
|
switch,
|
||||||
short = 'b',
|
short = 'b',
|
||||||
description = "set the profile to use on battery power"
|
description = "set the profile to use on battery power"
|
||||||
)]
|
)]
|
||||||
pub profile_set_bat: Option<PlatformProfile>,
|
pub battery: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(FromArgs, Debug, Default)]
|
#[derive(FromArgs, Debug, Default)]
|
||||||
|
|||||||
@@ -816,44 +816,37 @@ fn handle_throttle_profile(
|
|||||||
return Err(ProfileError::NotSupported.into());
|
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 proxy = PlatformProxyBlocking::new(conn)?;
|
||||||
let current = proxy.platform_profile()?;
|
let current = proxy.platform_profile()?;
|
||||||
let choices = proxy.platform_profile_choices()?;
|
let choices = proxy.platform_profile_choices()?;
|
||||||
|
|
||||||
if cmd.next {
|
match &cmd.command {
|
||||||
proxy.set_platform_profile(PlatformProfile::next(current, &choices))?;
|
crate::cli_opts::ProfileSubCommand::Next(_) => {
|
||||||
} else if let Some(profile) = cmd.profile_set {
|
proxy.set_platform_profile(PlatformProfile::next(current, &choices))?;
|
||||||
proxy.set_platform_profile(profile)?;
|
}
|
||||||
} else if let Some(profile) = cmd.profile_set_ac {
|
crate::cli_opts::ProfileSubCommand::Set(s) => {
|
||||||
proxy.set_platform_profile_on_ac(profile)?;
|
if !s.ac && !s.battery {
|
||||||
} else if let Some(profile) = cmd.profile_set_bat {
|
proxy.set_platform_profile(s.profile)?;
|
||||||
proxy.set_platform_profile_on_battery(profile)?;
|
} else {
|
||||||
}
|
if s.ac {
|
||||||
|
proxy.set_platform_profile_on_ac(s.profile)?;
|
||||||
if cmd.list {
|
}
|
||||||
for p in &choices {
|
if s.battery {
|
||||||
println!("{:?}", p);
|
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(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user