39 lines
785 B
Rust
39 lines
785 B
Rust
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),
|
|
)
|
|
}
|