Mercurial > templog
diff rust/src/main.rs @ 598:d4fbfb5c46ff rust
broken update of versions of things
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 07 Feb 2017 21:56:58 +0800 |
parents | a440eafa84a9 |
children | f71cf1ad745f |
line wrap: on
line diff
--- a/rust/src/main.rs Sat Jan 07 00:56:39 2017 +0800 +++ b/rust/src/main.rs Tue Feb 07 21:56:58 2017 +0800 @@ -1,8 +1,3 @@ -#![feature(plugin)] -#![plugin(docopt_macros)] - -#![feature(proc_macro)] - extern crate tokio_core; extern crate futures; #[macro_use] @@ -19,7 +14,6 @@ extern crate docopt; - use std::io; use tokio_core::reactor::Core; @@ -83,10 +77,10 @@ core.run(all).ok(); } -docopt!(Args, " +const USAGE: &'static str = "\ Wort Temperature Matt Johnston 2017 [email protected] -Usage: wort-templog [--help] [--new] [--daemon] [--debug] [--test] [--defconf] [--nowait] +Usage: wort-templog [--help] [--new] [--daemon] [--debug] [--test] [--defconf] [--thisconf] [--nowait] Options: -h, --help @@ -97,7 +91,18 @@ --nowait Skip initial fridge wait --defconf Print default config (customise in tempserver.conf) --thisconf Print used config -"); +"; + +#[derive(RustcDecodable)] +struct Args { + new: bool, + daemon: bool, + debug: bool, + test: bool, + defconf: bool, + thisconf: bool, + nowait: bool, +} fn setup_log(debug: bool) { let loglevel = if debug { @@ -119,42 +124,38 @@ } fn handle_args() -> Args { - let args: Args = Args::docopt().decode().unwrap_or_else(|e| e.exit()); + let args: Args = docopt::Docopt::new(USAGE).and_then(|d| d.decode()).unwrap_or_else(|e| e.exit()); - if args.flag_defconf { + if args.defconf { println!("Default configuration:\n{}\n\n{}", "(custom options go in tempserver.conf)", config::Config::new().to_toml_string()); std::process::exit(0); } - - args -} - -fn load_config(config: &mut Config) { - } fn main() { let mut config = config::Config::new(); let args = handle_args(); - setup_log(args.flag_debug); + setup_log(args.debug); //env_logger::init().unwrap(); info!("wort-templog"); debug!("debug mode"); - load_config(&mut config); + let conf_filename = "tempserver.conf"; + println!("parse config"); + config.parse(conf_filename) + .unwrap_or_else(|e| { + panic!("Couldn't parse {}: {}", conf_filename, e); + }); - let config = config; - - if args.flag_thisconf { - println!("current configuration:\n\n{}", + if args.thisconf { + println!("Current configuration:\n\n{}", config.to_toml_string()); } - - run(&config, args.flag_nowait, args.flag_test); + run(&config, args.nowait, args.test); }