Skip to content

Commit

Permalink
Merge pull request #208 from JakeRoggenbuck/log-view
Browse files Browse the repository at this point in the history
Add the most basic show config
  • Loading branch information
JakeRoggenbuck authored Feb 12, 2022
2 parents b3735db + b4aa290 commit d300b11
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 20 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -59,6 +66,18 @@ pub fn open_config() -> Result<Config, std::io::Error> {
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::*;
Expand Down
5 changes: 5 additions & 0 deletions src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::thread;

use termion::{color, style};

use super::config::get_config;
use super::cpu::CPU;
use super::power::LidState;

Expand Down Expand Up @@ -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);
Expand Down
21 changes: 7 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
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};
Expand Down Expand Up @@ -115,6 +115,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 {
Expand Down Expand Up @@ -160,18 +163,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;

Expand Down Expand Up @@ -251,6 +242,8 @@ fn parse_args(config: config::Config) {
},
},

ACSCommand::ShowConfig {} => show_config(),

// Run command
ACSCommand::Run {
quiet,
Expand Down

0 comments on commit d300b11

Please sign in to comment.