Mercurial > templog
view rust/src/main.rs @ 634:a5721c02d3ee rust
build succeeds
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sun, 22 Sep 2019 20:35:40 +0800 |
parents | 490e9e15b98c |
children | 4424a8b30f9c |
line wrap: on
line source
#![feature(async_closure)] #[macro_use] extern crate log; // riker has its own logging? //extern crate env_logger; #[macro_use] extern crate lazy_static; mod config; mod sensor; mod fridge; mod types; mod params; use crate::config::Config; use riker::actors::*; use structopt::StructOpt; fn run(cf: Config, nowait: bool, testmode: bool) { let sys = ActorSystem::new().unwrap(); let props = Props::new_args(params::ParamWaiter::new, cf.clone()); sys.actor_of(props, "paramwaiter").unwrap(); if testmode { let props = Props::new_args(sensor::TestSensor::new, cf.clone()); sys.actor_of(props, "sensor").unwrap() } else { let props = Props::new_args(sensor::OneWireSensor::new, cf.clone()); sys.actor_of(props, "sensor").unwrap() }; let props = Props::new_args(fridge::Fridge::new_actor, (cf.clone(), nowait)); sys.actor_of(props, "fridge").unwrap(); } #[derive(Debug, StructOpt)] #[structopt(name = "Wort Temperature", about = "Matt Johnston 2019 [email protected]")] struct Opt { /// Replace existing running instance #[structopt(long)] new: bool, /// Run in background #[structopt(short = "D", long)] daemon: bool, #[structopt(short, long)] debug: bool, /// Use fake sensors etc #[structopt(long)] test: bool, /// Skip initial fridge wait #[structopt(long)] nowait: bool, /// Print default config (customise in local.conf) #[structopt(long)] defconf: bool, } fn handle_args() -> Opt { let args = Opt::from_args(); if args.defconf { println!("Default configuration:\n{}\n\n{}", "(custom options go in local.conf)", config::Config::default_toml()); std::process::exit(0); } args } // fn setup_log(debug: bool) { // let loglevel = if debug { // log::LevelFilter::Debug // } else { // log::LevelFilter::Info // }; // let format = |record: &log::Record| { // let datefmt = "%Y-%m-%d %I:%M:%S %p"; // let ts = chrono::Local::now().format(datefmt); // format!("{}: {} - {}", ts, record.level(), record.args()) // }; // let mut builder = env_logger::Builder::new(); // builder.format(format).filter(Some("wort_templog"), loglevel); // builder.init().unwrap(); // } fn main() { let args = handle_args(); // setup_log(args.debug); //env_logger::init().unwrap(); info!("wort-templog"); debug!("debug mode"); let config = config::Config::load().unwrap(); run(config, args.nowait, args.test); }