feat: improve cmdline

This commit is contained in:
Denis Benato
2026-01-14 00:06:34 +01:00
parent e3035adf98
commit 7981a85ff5
2 changed files with 18 additions and 14 deletions

View File

@@ -10,9 +10,6 @@ use crate::slash_cli::SlashCommand;
#[derive(FromArgs, Default, Debug)]
/// asusctl command-line options
pub struct CliStart {
#[argh(switch, description = "show program version number")]
pub version: bool,
#[argh(switch, description = "show supported functions of this laptop")]
pub show_supported: bool,
@@ -49,6 +46,7 @@ pub enum CliCommand {
Scsi(ScsiCommand),
Armoury(ArmouryCommand),
Backlight(BacklightCommand),
Info(InfoCommand),
}
#[derive(FromArgs, Debug, Clone, Default)]
@@ -126,3 +124,11 @@ pub struct BacklightCommand {
)]
pub sync_screenpad_brightness: Option<bool>,
}
#[derive(FromArgs, Debug, Default)]
#[argh(
subcommand,
name = "info",
description = "show program version and system info"
)]
pub struct InfoCommand {}

View File

@@ -54,8 +54,6 @@ fn main() {
.format_timestamp(None)
.init();
let self_version = env!("CARGO_PKG_VERSION");
println!("Starting version {self_version}");
let parsed: CliStart = argh::from_env();
let conn = Connection::system().unwrap();
@@ -75,6 +73,7 @@ fn main() {
}
};
let self_version = env!("CARGO_PKG_VERSION");
if asusd_version != self_version {
println!("Version mismatch: asusctl = {self_version}, asusd = {asusd_version}");
return;
@@ -95,12 +94,6 @@ fn main() {
}
};
if parsed.version {
println!("asusctl v{}", env!("CARGO_PKG_VERSION"));
println!();
print_info();
}
if let Err(err) = do_parsed(&parsed, &supported_interfaces, &supported_properties, conn) {
print_error_help(&*err, &supported_interfaces, &supported_properties);
}
@@ -127,9 +120,9 @@ fn print_info() {
let dmi = DMIID::new().unwrap_or_default();
let board_name = dmi.board_name;
let prod_family = dmi.product_family;
println!("asusctl version: {}", env!("CARGO_PKG_VERSION"));
println!(" Product family: {}", prod_family.trim());
println!(" Board name: {}", board_name.trim());
println!("Software version: {}", env!("CARGO_PKG_VERSION"));
println!(" Product family: {}", prod_family.trim());
println!(" Board name: {}", board_name.trim());
}
fn check_service(name: &str) -> bool {
@@ -208,6 +201,11 @@ fn do_parsed(
Some(CliCommand::Scsi(cmd)) => handle_scsi(cmd)?,
Some(CliCommand::Armoury(cmd)) => handle_armoury_command(cmd)?,
Some(CliCommand::Backlight(cmd)) => handle_backlight(cmd)?,
Some(CliCommand::Info(_)) => {
println!("asusctl v{}", env!("CARGO_PKG_VERSION"));
println!();
print_info();
}
None => {
if !parsed.show_supported
&& parsed.kbd_bright.is_none()