1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
/* I'm playing around. Let me.
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_mut)]
#![allow(unused_imports)]
// */
#[macro_use] extern crate nom;
#[macro_use] extern crate log;
extern crate env_logger;
extern crate getopts;
extern crate mio;
extern crate slab;
extern crate netbuf;
mod config;
mod eventloop;
mod listener;
mod itf_http;
use std::process::exit;
use std::io::prelude::*;
struct CliOpts {
config: String,
}
impl CliOpts {
fn new() -> CliOpts {
CliOpts {
config: "/etc/webs.conf".to_string()
}
}
fn parse(mut self) -> CliOpts {
let mut args = std::env::args();
let prog = args.next().unwrap();
let mut opts = getopts::Options::new();
opts.optflag("h", "help", "print this help menu");
opts.optflag("V", "version", "show program version");
opts.optopt("c", "config", "config file", "FILE");
let m = match opts.parse(args) {
Ok(m) => { m }
Err(e) => {
let _ = writeln!(std::io::stderr(), "{}", e);
exit(1);
}
};
if m.opt_present("h") {
let _ = println!("{}", opts.usage(&prog));
exit(0);
}
if m.opt_present("V") {
let _ = println!("{} {}", prog, option_env!("CARGO_PKG_VERSION").unwrap_or(""));
exit(0);
}
if let Some(f) = m.opt_str("c") {
self.config = f;
}
self
}
}
fn main() {
let opts = CliOpts::new().parse();
let conf = config::Config::parse(&opts.config).unwrap();
env_logger::init().unwrap();
trace!("Configuration read from {}: {:?}", opts.config, conf);
let mut main = eventloop::EventLoop::new();
listener::setup(&mut main, &conf).unwrap();
main.run();
}
|