Initial commit
This commit is contained in:
commit
980a85d41b
15 changed files with 3969 additions and 0 deletions
38
src/main.rs
Normal file
38
src/main.rs
Normal 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),
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue