Initial commit

This commit is contained in:
Pascal Engélibert 2022-10-15 15:32:57 +02:00
commit 980a85d41b
Signed by: tuxmain
GPG key ID: 3504BC6D362F7DCA
15 changed files with 3969 additions and 0 deletions

38
src/main.rs Normal file
View file

@ -0,0 +1,38 @@
mod cli;
mod config;
mod db;
mod helpers;
mod queries;
mod server;
mod templates;
use clap::Parser;
#[async_std::main]
async fn main() {
let opt = cli::MainOpt::parse();
match opt.cmd {
cli::MainSubcommand::Init => {
init_all(opt.opt, cli::StartOpt { tmp: false });
}
cli::MainSubcommand::Start(subopt) => {
let (config, dbs, templates) = init_all(opt.opt, subopt);
server::start_server(config, dbs, templates).await
}
}
}
fn init_all(
opt: cli::MainCommonOpt,
subopt: cli::StartOpt,
) -> (config::Config, db::Dbs, templates::Templates) {
std::fs::create_dir_all(&opt.dir.0).expect("Cannot create dir");
let dbs = db::load_dbs((!subopt.tmp).then_some(&opt.dir.0));
(
config::read_config(&opt.dir.0),
dbs,
templates::Templates::new(&opt.dir.0),
)
}