From 13981d1e9d7a258f234fb0b0754513682fc022fa Mon Sep 17 00:00:00 2001 From: MusiKid Date: Sun, 7 Nov 2021 18:51:00 +0100 Subject: [PATCH] feat(cli): add status subcommand Closes #22 --- cli/extra/fancy.1.md | 10 +++++++++- cli/src/app.rs | 3 ++- cli/src/main.rs | 25 ++++++++++++++++++++----- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/cli/extra/fancy.1.md b/cli/extra/fancy.1.md index 56a594e..4cd3356 100644 --- a/cli/extra/fancy.1.md +++ b/cli/extra/fancy.1.md @@ -6,7 +6,7 @@ fancy - Fancy CLI # SYNOPSIS -`fancy get [speeds | temps | config]` +`fancy get [speeds | temps | config | auto | status]` `fancy set [-f FAN_SPEED [FAN_SPEEDS ...] | -a] [-c CONFIGURATION]` @@ -50,6 +50,14 @@ a set of software which allows to control laptop fans. : Get current configuration +`fancy get auto` + +: Get automatic speed management state + +`fancy get status` + +: Get summary + #### LIST List all available configurations diff --git a/cli/src/app.rs b/cli/src/app.rs index 3e0a490..629d3cd 100644 --- a/cli/src/app.rs +++ b/cli/src/app.rs @@ -52,7 +52,8 @@ pub fn get_app() -> App<'static, 'static> { .subcommand(SubCommand::with_name("speeds").about("Get the fans speeds")) .subcommand(SubCommand::with_name("temps").about("Get the temperatures")) .subcommand(SubCommand::with_name("config").about("Get the current config")) - .subcommand(SubCommand::with_name("auto").about("Get auto-handle state")), + .subcommand(SubCommand::with_name("auto").about("Get auto-handle state")) + .subcommand(SubCommand::with_name("status").about("Get summary")), ) .subcommand( SubCommand::with_name("list") diff --git a/cli/src/main.rs b/cli/src/main.rs index 8a27090..1ce7810 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -24,19 +24,34 @@ fn main() -> Result<(), anyhow::Error> { let matches = get_app().get_matches(); if let Some(matches) = matches.subcommand_matches("get") { - if matches.is_present("speeds") { + if matches.is_present("speeds") || matches.is_present("status") { + if matches.is_present("status") { + println!("Fans speeds"); + } let fans_speeds = proxy.fans_speeds()?; let names = proxy.fans_names()?; for (name, speed) in names.iter().zip(fans_speeds) { println!("{}: {:.1}%", name, speed); } - } else if matches.is_present("config") { + } + if matches.is_present("config") || matches.is_present("status") { + if matches.is_present("status") { + print!("\nConfig: "); + } let config = proxy.config()?; println!("{}", config); - } else if matches.is_present("auto") { + } + if matches.is_present("auto") || matches.is_present("status") { + if matches.is_present("status") { + print!("\nAuto-select thresholds: "); + } let auto = proxy.auto()?; - println!("Auto-select thresholds: {}", auto); - } else if matches.is_present("temps") { + println!("{}", auto); + } + if matches.is_present("temps") || matches.is_present("status") { + if matches.is_present("status") { + println!("\nTemperatures"); + } let temps = proxy.temperatures()?; for (sensor, temp) in temps { println!("{}: {:.1}°C", sensor, temp);