|
1 | 1 | #[macro_use] |
2 | 2 | extern crate log; |
| 3 | +extern crate getopts; |
3 | 4 |
|
| 5 | +use getopts::Options; |
4 | 6 | use rocket::config::Environment; |
| 7 | +use std::env; |
5 | 8 |
|
6 | 9 | use aw_server::*; |
7 | 10 |
|
| 11 | +fn print_usage(program: &str, opts: Options) { |
| 12 | + let brief = format!("Usage: {} FILE [options]", program); |
| 13 | + print!("{}", opts.usage(&brief)); |
| 14 | +} |
| 15 | + |
8 | 16 | fn main() { |
9 | 17 | use std::sync::Mutex; |
10 | 18 |
|
| 19 | + let args: Vec<String> = env::args().collect(); |
| 20 | + let program = args[0].clone(); |
| 21 | + |
| 22 | + let mut opts = Options::new(); |
| 23 | + opts.optflag("", "testing", "run in testing mode"); |
| 24 | + opts.optflag("h", "help", "print this help menu"); |
| 25 | + let matches = match opts.parse(&args[1..]) { |
| 26 | + Ok(m) => m, |
| 27 | + Err(f) => panic!(f.to_string()), |
| 28 | + }; |
| 29 | + if matches.opt_present("h") { |
| 30 | + print_usage(&program, opts); |
| 31 | + return; |
| 32 | + } |
| 33 | + |
11 | 34 | let env = Environment::active().expect("Failed to get current environment"); |
12 | | - let testing = match env { |
| 35 | + let mut testing = match env { |
13 | 36 | Environment::Production => false, |
14 | 37 | Environment::Development => true, |
15 | 38 | Environment::Staging => panic!("Staging environment not supported"), |
16 | 39 | }; |
| 40 | + // Always override environment if --testing is specified |
| 41 | + if matches.opt_present("testing") { |
| 42 | + testing = true; |
| 43 | + } |
17 | 44 |
|
18 | 45 | logging::setup_logger(testing).expect("Failed to setup logging"); |
19 | 46 |
|
@@ -45,7 +72,6 @@ use std::path::PathBuf; |
45 | 72 | // TODO: Should we talk to upstream about this? This changes the behavior quite a lot so maybe they |
46 | 73 | // don't want this change? |
47 | 74 | fn site_data_dir(app: Option<&str>, _: Option<&str>) -> Result<PathBuf, ()> { |
48 | | - use std::env; |
49 | 75 | // Iterate over all XDG_DATA_DIRS and return first match that exists |
50 | 76 | match env::var_os("XDG_DATA_DIRS") { |
51 | 77 | Some(joined) => { |
|
0 commit comments