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
#![allow(non_snake_case)]

#[macro_use] extern crate error;
mod skill_detail;
mod app;
mod config;

use std::path::Path;

use log::warn;

use error::Error;
use config::Configuration;

fn main() -> Result<(), Error>
{
    let opts = clap::Command::new("Breed web")
        .about("Dragon Warrior: Monsters 2 breed database web server")
        .arg(clap::Arg::new("serve-path")
             .long("serve-path")
             .short('p')
             .value_name("PATH")
             .help("Serve under PATH."))
        .arg(clap::Arg::new("config")
             .long("config")
             .short('c')
             .value_name("FILE")
             .default_value("/etc/breed-web.toml")
             .help("Path of config file."))
        .get_matches();

    env_logger::Builder::default().format_timestamp(None)
        .filter_level(log::LevelFilter::Info)
        .init();

    let config_path = opts.get_one::<String>("config").unwrap();
    let mut config = if Path::new(&config_path).exists()
    {
        Configuration::fromFile(&config_path)?
    }
    else
    {
        warn!("Config file not found. Using default config...");
        Configuration::default()
    };

    if let Some(p) = opts.get_one::<String>("serve-path")
    {
        config.serve_under_path = p.clone();
    }
    let a = app::App::new(config)?;
    tokio::runtime::Runtime::new().unwrap().block_on(a.serve())?;
    Ok(())
}