Mercurial > templog
comparison 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 |
comparison
equal
deleted
inserted
replaced
598:d4fbfb5c46ff | 599:f71cf1ad745f |
---|---|
93 --thisconf Print used config | 93 --thisconf Print used config |
94 "; | 94 "; |
95 | 95 |
96 #[derive(RustcDecodable)] | 96 #[derive(RustcDecodable)] |
97 struct Args { | 97 struct Args { |
98 new: bool, | 98 flag_new: bool, |
99 daemon: bool, | 99 flag_daemon: bool, |
100 debug: bool, | 100 flag_debug: bool, |
101 test: bool, | 101 flag_test: bool, |
102 defconf: bool, | 102 flag_defconf: bool, |
103 thisconf: bool, | 103 flag_thisconf: bool, |
104 nowait: bool, | 104 flag_nowait: bool, |
105 } | 105 } |
106 | 106 |
107 fn setup_log(debug: bool) { | 107 fn setup_log(debug: bool) { |
108 let loglevel = if debug { | 108 let loglevel = if debug { |
109 log::LogLevelFilter::Debug | 109 log::LogLevelFilter::Debug |
124 } | 124 } |
125 | 125 |
126 fn handle_args() -> Args { | 126 fn handle_args() -> Args { |
127 let args: Args = docopt::Docopt::new(USAGE).and_then(|d| d.decode()).unwrap_or_else(|e| e.exit()); | 127 let args: Args = docopt::Docopt::new(USAGE).and_then(|d| d.decode()).unwrap_or_else(|e| e.exit()); |
128 | 128 |
129 if args.defconf { | 129 if args.flag_defconf { |
130 println!("Default configuration:\n{}\n\n{}", | 130 println!("Default configuration:\n{}\n\n{}", |
131 "(custom options go in tempserver.conf)", | 131 "(custom options go in tempserver.conf)", |
132 config::Config::new().to_toml_string()); | 132 config::Config::default().to_toml_string()); |
133 std::process::exit(0); | 133 std::process::exit(0); |
134 } | 134 } |
135 args | |
135 } | 136 } |
136 | 137 |
137 fn main() { | 138 fn main() { |
138 let mut config = config::Config::new(); | 139 let mut config = config::Config::default(); |
139 | 140 |
140 let args = handle_args(); | 141 let args = handle_args(); |
141 setup_log(args.debug); | 142 setup_log(args.flag_debug); |
142 //env_logger::init().unwrap(); | 143 //env_logger::init().unwrap(); |
143 | 144 |
144 info!("wort-templog"); | 145 info!("wort-templog"); |
145 debug!("debug mode"); | 146 debug!("debug mode"); |
146 | 147 |
147 let conf_filename = "tempserver.conf"; | 148 let conf_filename = "tempserver.conf"; |
148 println!("parse config"); | 149 config = config.merge_file(conf_filename) |
149 config.parse(conf_filename) | |
150 .unwrap_or_else(|e| { | 150 .unwrap_or_else(|e| { |
151 panic!("Couldn't parse {}: {}", conf_filename, e); | 151 panic!("Couldn't parse {}: {}", conf_filename, e); |
152 }); | 152 }); |
153 | 153 |
154 if args.thisconf { | 154 if args.flag_thisconf { |
155 println!("Current configuration:\n\n{}", | 155 println!("Current configuration:\n\n{}", |
156 config.to_toml_string()); | 156 config.to_toml_string()); |
157 std::process::exit(0); | |
157 } | 158 } |
158 | 159 |
159 run(&config, args.nowait, args.test); | 160 run(&config, args.flag_nowait, args.flag_test); |
160 } | 161 } |
161 | 162 |