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"
|
description = "armoury / firmware attributes"
|
||||||
)]
|
)]
|
||||||
pub struct ArmouryCommand {
|
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(
|
#[argh(
|
||||||
positional,
|
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)]
|
#[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)]
|
#[allow(clippy::manual_is_multiple_of, clippy::nonminimal_bool)]
|
||||||
fn handle_armoury_command(cmd: &ArmouryCommand) -> Result<(), Box<dyn std::error::Error>> {
|
fn handle_armoury_command(cmd: &ArmouryCommand) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
{
|
// If nested subcommand provided, handle set/get/list.
|
||||||
if cmd.free.is_empty() || (cmd.free.len() % 2 != 0) {
|
match &cmd.command {
|
||||||
const USAGE: &str = "Usage: asusctl armoury panel_overdrive 1 nv_dynamic_boost 5";
|
ArmourySubCommand::List(_) => {
|
||||||
if cmd.free.len() % 2 != 0 {
|
if let Ok(attrs) = find_iface::<AsusArmouryProxyBlocking>("xyz.ljones.AsusArmoury") {
|
||||||
println!(
|
for attr in attrs.iter() {
|
||||||
"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() {
|
|
||||||
print_firmware_attr(attr)?;
|
print_firmware_attr(attr)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
ArmourySubCommand::Get(g) => {
|
||||||
if let Ok(attr) = find_iface::<AsusArmouryProxyBlocking>("xyz.ljones.AsusArmoury") {
|
if let Ok(attrs) = find_iface::<AsusArmouryProxyBlocking>("xyz.ljones.AsusArmoury") {
|
||||||
for cmd in cmd.free.chunks(2) {
|
for attr in attrs.iter() {
|
||||||
for attr in attr.iter() {
|
|
||||||
let name = attr.name()?;
|
let name = attr.name()?;
|
||||||
if <&str>::from(name) == cmd[0] {
|
if <&str>::from(name) == g.property {
|
||||||
let mut value: i32 = cmd[1].parse()?;
|
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 {
|
if value == -1 {
|
||||||
info!("Setting to default");
|
info!("Setting to default");
|
||||||
value = attr.default_value()?;
|
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