feat: improve the cli interface

This commit is contained in:
Denis Benato
2026-01-14 01:56:58 +01:00
parent d7ddee246a
commit 3665d9cc8e
2 changed files with 67 additions and 43 deletions

View File

@@ -216,6 +216,7 @@ pub struct SingleSpeed {
#[argh( #[argh(
option, option,
default = "AuraZone::None",
description = "set the zone for this effect e.g. 0, 1, one, logo, lightbar-left" description = "set the zone for this effect e.g. 0, 1, one, logo, lightbar-left"
)] )]
pub zone: AuraZone, pub zone: AuraZone,
@@ -237,6 +238,7 @@ pub struct SingleSpeedDirection {
#[argh( #[argh(
option, option,
default = "AuraZone::None",
description = "set the zone for this effect e.g. 0, 1, one, logo, lightbar-left" description = "set the zone for this effect e.g. 0, 1, one, logo, lightbar-left"
)] )]
pub zone: AuraZone, pub zone: AuraZone,
@@ -250,11 +252,12 @@ pub struct SingleSpeedDirection {
description = "static single-colour effect" description = "static single-colour effect"
)] )]
pub struct SingleColour { pub struct SingleColour {
#[argh(option, description = "set the RGB value e.g. ff00ff")] #[argh(option, short = 'c', description = "set the RGB value e.g. ff00ff")]
pub colour: Colour, pub colour: Colour,
#[argh( #[argh(
option, option,
default = "AuraZone::None",
description = "set the zone for this effect e.g. 0, 1, one, logo, lightbar-left" description = "set the zone for this effect e.g. 0, 1, one, logo, lightbar-left"
)] )]
pub zone: AuraZone, pub zone: AuraZone,
@@ -268,7 +271,7 @@ pub struct SingleColour {
description = "single-colour effect with speed" description = "single-colour effect with speed"
)] )]
pub struct SingleColourSpeed { pub struct SingleColourSpeed {
#[argh(option, description = "set the RGB value e.g. ff00ff")] #[argh(option, short = 'c', description = "set the RGB value e.g. ff00ff")]
pub colour: Colour, pub colour: Colour,
#[argh(option, description = "set the speed: low, med, high")] #[argh(option, description = "set the speed: low, med, high")]
@@ -276,6 +279,7 @@ pub struct SingleColourSpeed {
#[argh( #[argh(
option, option,
default = "AuraZone::None",
description = "set the zone for this effect e.g. 0, 1, one, logo, lightbar-left" description = "set the zone for this effect e.g. 0, 1, one, logo, lightbar-left"
)] )]
pub zone: AuraZone, pub zone: AuraZone,
@@ -300,6 +304,7 @@ pub struct TwoColourSpeed {
#[argh( #[argh(
option, option,
default = "AuraZone::None",
description = "set the zone for this effect e.g. 0, 1, one, logo, lightbar-left" description = "set the zone for this effect e.g. 0, 1, one, logo, lightbar-left"
)] )]
pub zone: AuraZone, pub zone: AuraZone,

View File

@@ -198,50 +198,69 @@ fn do_parsed(
CliCommand::Scsi(cmd) => handle_scsi(cmd)?, CliCommand::Scsi(cmd) => handle_scsi(cmd)?,
CliCommand::Armoury(cmd) => handle_armoury_command(cmd)?, CliCommand::Armoury(cmd) => handle_armoury_command(cmd)?,
CliCommand::Backlight(cmd) => handle_backlight(cmd)?, CliCommand::Backlight(cmd) => handle_backlight(cmd)?,
CliCommand::Battery(cmd) => match &cmd.command { CliCommand::Battery(cmd) => handle_battery(cmd, &conn)?,
BatterySubCommand::Limit(l) => {
let proxy = PlatformProxyBlocking::new(&conn)?;
proxy.set_charge_control_end_threshold(l.limit)?;
}
BatterySubCommand::OneShot(o) => {
let proxy = PlatformProxyBlocking::new(&conn)?;
if let Some(p) = o.percent {
proxy.set_charge_control_end_threshold(p)?;
}
proxy.one_shot_full_charge()?;
}
BatterySubCommand::Info(_) => {
let proxy = PlatformProxyBlocking::new(&conn)?;
let limit = proxy.charge_control_end_threshold()?;
println!("Current battery charge limit: {}%", limit);
}
},
CliCommand::Info(info_opt) => { CliCommand::Info(info_opt) => {
println!("asusctl v{}", env!("CARGO_PKG_VERSION")); handle_info(info_opt, supported_interfaces, supported_properties)?
println!(); }
print_info(); }
println!();
if info_opt.show_supported { Ok(())
println!("Supported Core Functions:\n{:#?}", supported_interfaces); }
println!(
"Supported Platform Properties:\n{:#?}", fn handle_battery(
supported_properties cmd: &BatteryCommand,
); conn: &Connection,
if let Ok(aura) = find_iface::<AuraProxyBlocking>("xyz.ljones.Aura") { ) -> Result<(), Box<dyn std::error::Error>> {
// TODO: multiple RGB check match &cmd.command {
let bright = aura.first().unwrap().supported_brightness()?; BatterySubCommand::Limit(l) => {
let modes = aura.first().unwrap().supported_basic_modes()?; let proxy = PlatformProxyBlocking::new(conn)?;
let zones = aura.first().unwrap().supported_basic_zones()?; proxy.set_charge_control_end_threshold(l.limit)?;
let power = aura.first().unwrap().supported_power_zones()?; }
println!("Supported Keyboard Brightness:\n{:#?}", bright); BatterySubCommand::OneShot(o) => {
println!("Supported Aura Modes:\n{:#?}", modes); let proxy = PlatformProxyBlocking::new(conn)?;
println!("Supported Aura Zones:\n{:#?}", zones); if let Some(p) = o.percent {
println!("Supported Aura Power Zones:\n{:#?}", power); proxy.set_charge_control_end_threshold(p)?;
} else {
println!("No aura interface found");
}
} }
proxy.one_shot_full_charge()?;
}
BatterySubCommand::Info(_) => {
let proxy = PlatformProxyBlocking::new(conn)?;
let limit = proxy.charge_control_end_threshold()?;
println!("Current battery charge limit: {}%", limit);
}
}
Ok(())
}
fn handle_info(
info_opt: &InfoCommand,
supported_interfaces: &[String],
supported_properties: &[Properties],
) -> Result<(), Box<dyn std::error::Error>> {
println!("asusctl v{}", env!("CARGO_PKG_VERSION"));
println!();
print_info();
println!();
if info_opt.show_supported {
println!("Supported Core Functions:\n{:#?}", supported_interfaces);
println!(
"Supported Platform Properties:\n{:#?}",
supported_properties
);
if let Ok(aura) = find_iface::<AuraProxyBlocking>("xyz.ljones.Aura") {
// TODO: multiple RGB check
let bright = aura.first().unwrap().supported_brightness()?;
let modes = aura.first().unwrap().supported_basic_modes()?;
let zones = aura.first().unwrap().supported_basic_zones()?;
let power = aura.first().unwrap().supported_power_zones()?;
println!("Supported Keyboard Brightness:\n{:#?}", bright);
println!("Supported Aura Modes:\n{:#?}", modes);
println!("Supported Aura Zones:\n{:#?}", zones);
println!("Supported Aura Power Zones:\n{:#?}", power);
} else {
println!("No aura interface found");
} }
} }