diff --git a/Cargo.lock b/Cargo.lock index e4a25741..d69899ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -85,9 +85,9 @@ dependencies = [ [[package]] name = "clap" -version = "2.33.3" +version = "2.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" +checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" dependencies = [ "bitflags", "textwrap", @@ -148,9 +148,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.98" +version = "0.2.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "320cfe77175da3a483efed4bc0adc1968ca050b098ce4f2f1c13a56626128790" +checksum = "e74d72e0f9b65b5b4ca49a346af3976df0f9c61d550727f349ecd559f251a26c" [[package]] name = "log" @@ -411,9 +411,9 @@ checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" [[package]] name = "unicode-width" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" +checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" [[package]] name = "unicode-xid" diff --git a/src/config.rs b/src/config.rs index 0284a4ce..2beb1f74 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,5 +1,6 @@ use super::warn_user; use serde::{Deserialize, Serialize}; +use std::fmt; use std::fs::File; use std::io::Read; use std::path::Path; @@ -28,6 +29,12 @@ pub struct Config { // pub charging_powersave_under: i32, } +impl fmt::Display for Config { + fn fmt(&self, f: &mut std::fmt::Formatter) -> fmt::Result { + write!(f, "powersave_under = {}", self.powersave_under) + } +} + pub fn default_config() -> Config { Config { powersave_under: 20, @@ -70,6 +77,18 @@ pub fn open_config() -> Result { Ok(config_toml) } +pub fn get_config() -> Config { + // Config will always exist, default or otherwise + match open_config() { + Ok(conf) => conf, + Err(_) => { + warn_user!("Using default config. Create file '/etc/acs/acs.toml' for custom config."); + // Use default config as config + default_config() + } + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/display.rs b/src/display.rs index 21e0a564..fee0ab5c 100644 --- a/src/display.rs +++ b/src/display.rs @@ -3,6 +3,7 @@ use std::thread; use termion::{color, style}; +use super::config::get_config; use super::cpu::CPU; use super::power::LidState; @@ -45,6 +46,10 @@ macro_rules! create_issue { }}; } +pub fn show_config() { + println!("{}", get_config()); +} + pub fn print_freq(f: i32, raw: bool) { if raw { println!("{}", f); diff --git a/src/main.rs b/src/main.rs index b5a886af..391b4f2a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,11 +3,11 @@ use std::process::exit; use log::debug; use structopt::StructOpt; -use config::{config_dir_exists, default_config, open_config}; +use config::{config_dir_exists, get_config}; use daemon::{daemon_init, Checker}; use display::{ print_available_governors, print_cpu_governors, print_cpu_speeds, print_cpu_temp, print_cpus, - print_freq, print_power, print_turbo, + print_freq, print_power, print_turbo, show_config, }; use error::Error; use power::{read_battery_charge, read_lid_state, read_power_source}; @@ -114,6 +114,9 @@ enum ACSCommand { set: SetType, }, + #[structopt(name = "showconfig", alias = "conf")] + ShowConfig {}, + /// Run the daemon, this checks and edit your cpu's speed #[structopt(name = "run")] Run { @@ -159,18 +162,6 @@ enum ACSCommand { }, } -fn get_config() -> config::Config { - // Config will always exist, default or otherwise - match open_config() { - Ok(conf) => conf, - Err(_) => { - warn_user!("Using default config. Create file '/etc/acs/acs.toml' for custom config."); - // Use default config as config - default_config() - } - } -} - fn parse_args(config: config::Config) { let mut daemon: daemon::Daemon; @@ -241,6 +232,8 @@ fn parse_args(config: config::Config) { }, }, + ACSCommand::ShowConfig {} => show_config(), + // Run command ACSCommand::Run { quiet,