Mercurial > templog
comparison rust/src/main.rs @ 632:bde302def78e rust
moving to riker, nowhere near yet
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 22 Aug 2019 23:59:50 +0800 |
parents | c57821a60e51 |
children | 490e9e15b98c |
comparison
equal
deleted
inserted
replaced
631:c57821a60e51 | 632:bde302def78e |
---|---|
1 #![feature(proc_macro, conservative_impl_trait, generators)] | 1 #[macro_use] extern crate log; |
2 #![feature(await_macro, async_await, futures_api)] | 2 // riker has its own logging? |
3 //extern crate env_logger; | |
3 | 4 |
4 | |
5 #[macro_use] | |
6 extern crate tokio; | |
7 #[macro_use] | |
8 extern crate futures; | |
9 | |
10 #[macro_use] | |
11 extern crate log; | |
12 extern crate env_logger; | |
13 extern crate rustc_serialize; | |
14 extern crate time; | |
15 extern crate serde_json; | |
16 extern crate libc; | |
17 extern crate atomicwrites; | |
18 extern crate hyper; | |
19 | |
20 #[macro_use] | |
21 extern crate lazy_static; | |
22 | |
23 #[macro_use] | |
24 extern crate serde_derive; | |
25 extern crate serde; | |
26 | |
27 extern crate toml; | |
28 | |
29 extern crate docopt; | |
30 | |
31 use std::io; | |
32 | |
33 use tokio_core::reactor:: Core; | |
34 use futures::{Stream,Sink,Future}; | |
35 use futures::sync::{mpsc}; | |
36 use sensor::Sensor; | 5 use sensor::Sensor; |
37 | 6 |
38 mod config; | 7 mod config; |
39 mod sensor; | 8 mod sensor; |
40 mod fridge; | 9 mod fridge; |
120 flag_defconf: bool, | 89 flag_defconf: bool, |
121 flag_thisconf: bool, | 90 flag_thisconf: bool, |
122 flag_nowait: bool, | 91 flag_nowait: bool, |
123 } | 92 } |
124 | 93 |
94 fn handle_args() -> Args { | |
95 let args: Args = docopt::Docopt::new(USAGE).and_then(|d| d.decode()).unwrap_or_else(|e| e.exit()); | |
96 | |
97 if args.flag_defconf { | |
98 println!("Default configuration:\n{}\n\n{}", | |
99 "(custom options go in local.conf)", | |
100 config::Config::default().to_toml_string()); | |
101 std::process::exit(0); | |
102 } | |
103 args | |
104 } | |
105 | |
125 fn setup_log(debug: bool) { | 106 fn setup_log(debug: bool) { |
126 let loglevel = if debug { | 107 let loglevel = if debug { |
127 log::LogLevelFilter::Debug | 108 log::LogLevelFilter::Debug |
128 } else { | 109 } else { |
129 log::LogLevelFilter::Info | 110 log::LogLevelFilter::Info |
137 | 118 |
138 | 119 |
139 let mut builder = env_logger::LogBuilder::new(); | 120 let mut builder = env_logger::LogBuilder::new(); |
140 builder.format(format).filter(Some("wort_templog"), loglevel); | 121 builder.format(format).filter(Some("wort_templog"), loglevel); |
141 builder.init().unwrap(); | 122 builder.init().unwrap(); |
142 } | |
143 | |
144 fn handle_args() -> Args { | |
145 let args: Args = docopt::Docopt::new(USAGE).and_then(|d| d.decode()).unwrap_or_else(|e| e.exit()); | |
146 | |
147 if args.flag_defconf { | |
148 println!("Default configuration:\n{}\n\n{}", | |
149 "(custom options go in local.conf)", | |
150 config::Config::default().to_toml_string()); | |
151 std::process::exit(0); | |
152 } | |
153 args | |
154 } | 123 } |
155 | 124 |
156 fn load_config() -> Config { | 125 fn load_config() -> Config { |
157 let nconfig = config::Config::default(); | 126 let nconfig = config::Config::default(); |
158 | 127 |