gmarche-rs/src/main.rs

38 lines
783 B
Rust
Raw Normal View History

2020-10-26 23:43:18 +01:00
#![feature(bool_to_option)]
mod cli;
mod config;
mod db;
2020-12-17 10:05:26 +01:00
mod queries;
2020-10-26 23:43:18 +01:00
mod server;
mod static_files;
mod templates;
2020-12-08 19:53:30 +01:00
mod utils;
2020-10-26 23:43:18 +01:00
use structopt::StructOpt;
2020-12-17 10:05:26 +01:00
#[async_std::main]
2020-10-26 23:43:18 +01:00
async fn main() {
let opt = cli::MainOpt::from_args();
match opt.cmd {
cli::MainSubcommand::Init => {
init_all(opt);
}
cli::MainSubcommand::Start => {
let (config, dbs, templates) = init_all(opt.clone());
server::start_server(config, dbs, templates, opt).await
}
}
}
fn init_all<'reg>(opt: cli::MainOpt) -> (config::Config, db::Dbs, templates::Templates<'reg>) {
std::fs::create_dir_all(&opt.dir.0).expect("Cannot create dir");
static_files::init_static_files(&opt.dir.0);
(
config::read_config(&opt.dir.0),
db::load_dbs(&opt.dir.0),
templates::load_templates(&opt.dir.0),
)
}