Skip to content

Commit

Permalink
feat: poweroff log
Browse files Browse the repository at this point in the history
  • Loading branch information
fengyc committed Aug 30, 2022
1 parent 76ae064 commit 322761d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions pisugar-poweroff/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ homepage = "https://github.com/PiSugar/pisugar-power-manager-rs"
[dependencies]
clap = "3"
pisugar-core = { path = "../pisugar-core" }
env_logger = "0.9"


[[bin]]
Expand Down
13 changes: 12 additions & 1 deletion pisugar-poweroff/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::time::Duration;

use clap::{Arg, Command};

use env_logger::Env;
use pisugar_core::{Model, PiSugarConfig, PiSugarCore, Result};
use std::convert::TryInto;

Expand All @@ -29,6 +30,14 @@ fn main() {
.version(env!("CARGO_PKG_VERSION"))
.author(env!("CARGO_PKG_AUTHORS"))
.about(env!("CARGO_PKG_DESCRIPTION"))
.arg(
Arg::new("log")
.short('l')
.long("log")
.takes_value(true)
.default_value("info")
.help("Log level, debug/info/warn/error"),
)
.arg(
Arg::new("model")
.short('m')
Expand Down Expand Up @@ -72,7 +81,7 @@ fn main() {
.get_matches();

let model: Model = matches.value_of("model").unwrap().try_into().unwrap();

let log_level = matches.value_of("log").unwrap();
let countdown: u64 = matches.value_of("countdown").unwrap().parse().unwrap();
let retries: u32 = matches.value_of("retries").unwrap().parse().unwrap();
let config_file: &str = matches.value_of("configfile").unwrap();
Expand All @@ -82,6 +91,8 @@ fn main() {
}
eprint!("0...\n");

env_logger::Builder::from_env(Env::default().default_filter_or(log_level)).init();

let mut config = PiSugarConfig::default();
let _ = config.load(Path::new(config_file));
let _ = shutdown(config, model, retries);
Expand Down

0 comments on commit 322761d

Please sign in to comment.