56 lines
1.0 KiB
Rust
56 lines
1.0 KiB
Rust
#![feature(bool_to_option)]
|
|
|
|
mod cli;
|
|
mod config;
|
|
mod db;
|
|
mod queries;
|
|
mod server;
|
|
mod static_files;
|
|
mod templates;
|
|
mod utils;
|
|
|
|
use utils::*;
|
|
|
|
use clap::Parser;
|
|
|
|
#[async_std::main]
|
|
async fn main() {
|
|
let opt = cli::MainOpt::parse();
|
|
|
|
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);
|
|
let dbs = db::load_dbs(&opt.dir.0);
|
|
|
|
if !dbs.group.contains_key(&ROOT_GROUP_ID).unwrap() {
|
|
dbs.group
|
|
.insert(
|
|
ROOT_GROUP_ID,
|
|
bincode::serialize(&Group {
|
|
name: String::new(),
|
|
parent: ROOT_GROUP_ID,
|
|
title: String::from("ĞMarché"),
|
|
})
|
|
.unwrap(),
|
|
)
|
|
.unwrap();
|
|
}
|
|
|
|
(
|
|
config::read_config(&opt.dir.0),
|
|
dbs,
|
|
templates::load_templates(&opt.dir.0),
|
|
)
|
|
}
|