diff --git a/asusctl/src/cli_opts.rs b/asusctl/src/cli_opts.rs index b7a7abf2..559863ab 100644 --- a/asusctl/src/cli_opts.rs +++ b/asusctl/src/cli_opts.rs @@ -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, + 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)] diff --git a/asusctl/src/main.rs b/asusctl/src/main.rs index 9add5b99..dad20baa 100644 --- a/asusctl/src/main.rs +++ b/asusctl/src/main.rs @@ -1009,33 +1009,33 @@ fn print_firmware_attr(attr: &AsusArmouryProxyBlocking) -> Result<(), Box Result<(), Box> { - { - 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::("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::("xyz.ljones.AsusArmoury") { + for attr in attrs.iter() { print_firmware_attr(attr)?; } } return Ok(()); } - - if let Ok(attr) = find_iface::("xyz.ljones.AsusArmoury") { - for cmd in cmd.free.chunks(2) { - for attr in attr.iter() { + ArmourySubCommand::Get(g) => { + if let Ok(attrs) = find_iface::("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::("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