breed_web/
main.rs

1#![allow(non_snake_case)]
2
3#[macro_use] extern crate error;
4mod skill_detail;
5mod app;
6mod config;
7
8use std::path::Path;
9
10use log::warn;
11
12use error::Error;
13use config::Configuration;
14
15fn main() -> Result<(), Error>
16{
17    let opts = clap::Command::new("Breed web")
18        .about("Dragon Warrior: Monsters 2 breed database web server")
19        .arg(clap::Arg::new("serve-path")
20             .long("serve-path")
21             .short('p')
22             .value_name("PATH")
23             .help("Serve under PATH."))
24        .arg(clap::Arg::new("config")
25             .long("config")
26             .short('c')
27             .value_name("FILE")
28             .default_value("/etc/breed-web.toml")
29             .help("Path of config file."))
30        .get_matches();
31
32    env_logger::Builder::default().format_timestamp(None)
33        .filter_level(log::LevelFilter::Info)
34        .init();
35
36    let config_path = opts.get_one::<String>("config").unwrap();
37    let mut config = if Path::new(&config_path).exists()
38    {
39        Configuration::fromFile(&config_path)?
40    }
41    else
42    {
43        warn!("Config file not found. Using default config...");
44        Configuration::default()
45    };
46
47    if let Some(p) = opts.get_one::<String>("serve-path")
48    {
49        config.serve_under_path = p.clone();
50    }
51    let a = app::App::new(config)?;
52    tokio::runtime::Runtime::new().unwrap().block_on(a.serve())?;
53    Ok(())
54}