diff rust/src/main.rs @ 599:f71cf1ad745f rust

updated toml serde works OK
author Matt Johnston <matt@ucc.asn.au>
date Tue, 07 Feb 2017 22:35:29 +0800
parents d4fbfb5c46ff
children 8c21df3711e2
line wrap: on
line diff
--- a/rust/src/main.rs	Tue Feb 07 21:56:58 2017 +0800
+++ b/rust/src/main.rs	Tue Feb 07 22:35:29 2017 +0800
@@ -95,13 +95,13 @@
 
 #[derive(RustcDecodable)]
 struct Args {
-    new: bool,
-    daemon: bool,
-    debug: bool,
-    test: bool,
-    defconf: bool,
-    thisconf: bool,
-    nowait: bool,
+    flag_new: bool,
+    flag_daemon: bool,
+    flag_debug: bool,
+    flag_test: bool,
+    flag_defconf: bool,
+    flag_thisconf: bool,
+    flag_nowait: bool,
 }
 
 fn setup_log(debug: bool) {
@@ -126,36 +126,37 @@
 fn handle_args() -> Args {
     let args: Args = docopt::Docopt::new(USAGE).and_then(|d| d.decode()).unwrap_or_else(|e| e.exit());
 
-    if args.defconf {
+    if args.flag_defconf {
         println!("Default configuration:\n{}\n\n{}",
             "(custom options go in tempserver.conf)",
-            config::Config::new().to_toml_string());
+            config::Config::default().to_toml_string());
         std::process::exit(0);
     }
+    args
 }
 
 fn main() {
-    let mut config = config::Config::new();
+    let mut config = config::Config::default();
 
     let args = handle_args();
-    setup_log(args.debug);
+    setup_log(args.flag_debug);
     //env_logger::init().unwrap();
 
     info!("wort-templog");
     debug!("debug mode");
 
     let conf_filename = "tempserver.conf";
-    println!("parse config");
-    config.parse(conf_filename)
+    config = config.merge_file(conf_filename)
         .unwrap_or_else(|e| {
             panic!("Couldn't parse {}: {}", conf_filename, e);
     });
 
-    if args.thisconf {
+    if args.flag_thisconf {
         println!("Current configuration:\n\n{}",
             config.to_toml_string());
+        std::process::exit(0);
     }
 
-    run(&config, args.nowait, args.test);
+    run(&config, args.flag_nowait, args.flag_test);
 }