mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-01-22 09:23:19 +01:00
feat: make easier to use armoury subcommand
This commit is contained in:
@@ -99,11 +99,61 @@ pub struct LedModeCommand {
|
||||
description = "armoury / firmware attributes"
|
||||
)]
|
||||
pub struct ArmouryCommand {
|
||||
#[argh(subcommand)]
|
||||
pub command: ArmourySubCommand,
|
||||
}
|
||||
|
||||
#[derive(FromArgs, Debug)]
|
||||
#[argh(subcommand)]
|
||||
pub enum ArmourySubCommand {
|
||||
Set(ArmouryPropertySetCommand),
|
||||
Get(ArmouryPropertyGetCommand),
|
||||
List(ArmouryPropertyListCommand),
|
||||
}
|
||||
|
||||
impl Default for ArmourySubCommand {
|
||||
fn default() -> Self {
|
||||
ArmourySubCommand::List(ArmouryPropertyListCommand::default())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(FromArgs, Debug, Default)]
|
||||
#[argh(
|
||||
subcommand,
|
||||
name = "set",
|
||||
description = "set an asus-armoury firmware-attribute"
|
||||
)]
|
||||
pub struct ArmouryPropertySetCommand {
|
||||
#[argh(
|
||||
positional,
|
||||
description = "append each value name followed by the value to set. `-1` sets to default"
|
||||
description = "name of the attribute to set (see asus-armoury list for available properties)"
|
||||
)]
|
||||
pub free: Vec<String>,
|
||||
pub property: String,
|
||||
|
||||
#[argh(positional, description = "value to set for the given attribute")]
|
||||
pub value: i32,
|
||||
}
|
||||
|
||||
#[derive(FromArgs, Debug, Default)]
|
||||
#[argh(
|
||||
subcommand,
|
||||
name = "list",
|
||||
description = "list all firmware-attributes supported by asus-armoury"
|
||||
)]
|
||||
pub struct ArmouryPropertyListCommand {}
|
||||
|
||||
#[derive(FromArgs, Debug, Default)]
|
||||
#[argh(
|
||||
subcommand,
|
||||
name = "get",
|
||||
description = "get a firmware-attribute from asus-armoury"
|
||||
)]
|
||||
pub struct ArmouryPropertyGetCommand {
|
||||
#[argh(
|
||||
positional,
|
||||
description = "name of the property to get (see asus-armoury list for available properties)"
|
||||
)]
|
||||
pub property: String,
|
||||
}
|
||||
|
||||
#[derive(FromArgs, Debug, Default)]
|
||||
|
||||
@@ -1009,33 +1009,33 @@ fn print_firmware_attr(attr: &AsusArmouryProxyBlocking) -> Result<(), Box<dyn st
|
||||
|
||||
#[allow(clippy::manual_is_multiple_of, clippy::nonminimal_bool)]
|
||||
fn handle_armoury_command(cmd: &ArmouryCommand) -> Result<(), Box<dyn std::error::Error>> {
|
||||
{
|
||||
if cmd.free.is_empty() || (cmd.free.len() % 2 != 0) {
|
||||
const USAGE: &str = "Usage: asusctl armoury panel_overdrive 1 nv_dynamic_boost 5";
|
||||
if cmd.free.len() % 2 != 0 {
|
||||
println!(
|
||||
"Incorrect number of args, each attribute label must be paired with a setting:"
|
||||
);
|
||||
println!("{USAGE}");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let Ok(attr) = find_iface::<AsusArmouryProxyBlocking>("xyz.ljones.AsusArmoury") {
|
||||
println!("\n{USAGE}\n");
|
||||
println!("Available firmware attributes: ");
|
||||
for attr in attr.iter() {
|
||||
// If nested subcommand provided, handle set/get/list.
|
||||
match &cmd.command {
|
||||
ArmourySubCommand::List(_) => {
|
||||
if let Ok(attrs) = find_iface::<AsusArmouryProxyBlocking>("xyz.ljones.AsusArmoury") {
|
||||
for attr in attrs.iter() {
|
||||
print_firmware_attr(attr)?;
|
||||
}
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let Ok(attr) = find_iface::<AsusArmouryProxyBlocking>("xyz.ljones.AsusArmoury") {
|
||||
for cmd in cmd.free.chunks(2) {
|
||||
for attr in attr.iter() {
|
||||
ArmourySubCommand::Get(g) => {
|
||||
if let Ok(attrs) = find_iface::<AsusArmouryProxyBlocking>("xyz.ljones.AsusArmoury") {
|
||||
for attr in attrs.iter() {
|
||||
let name = attr.name()?;
|
||||
if <&str>::from(name) == cmd[0] {
|
||||
let mut value: i32 = cmd[1].parse()?;
|
||||
if <&str>::from(name) == g.property {
|
||||
print_firmware_attr(attr)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
ArmourySubCommand::Set(s) => {
|
||||
if let Ok(attrs) = find_iface::<AsusArmouryProxyBlocking>("xyz.ljones.AsusArmoury") {
|
||||
for attr in attrs.iter() {
|
||||
let name = attr.name()?;
|
||||
if <&str>::from(name) == s.property {
|
||||
let mut value: i32 = s.value;
|
||||
if value == -1 {
|
||||
info!("Setting to default");
|
||||
value = attr.default_value()?;
|
||||
@@ -1045,7 +1045,7 @@ fn handle_armoury_command(cmd: &ArmouryCommand) -> Result<(), Box<dyn std::error
|
||||
}
|
||||
}
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user