2020-11-29 20:22:40 +00:00
|
|
|
#![warn (clippy::pedantic)]
|
|
|
|
|
2020-11-01 03:17:11 +00:00
|
|
|
use std::{
|
|
|
|
path::PathBuf,
|
|
|
|
};
|
|
|
|
|
|
|
|
use structopt::StructOpt;
|
2020-11-09 00:53:07 +00:00
|
|
|
use tokio::runtime;
|
2020-11-27 00:50:22 +00:00
|
|
|
|
|
|
|
use ptth_server::{
|
|
|
|
ConfigFile,
|
|
|
|
load_toml,
|
|
|
|
run_server,
|
|
|
|
};
|
2020-11-06 04:18:47 +00:00
|
|
|
|
2020-11-01 03:17:11 +00:00
|
|
|
#[derive (Debug, StructOpt)]
|
|
|
|
struct Opt {
|
2020-11-18 22:48:15 +00:00
|
|
|
//#[structopt (long)]
|
|
|
|
//file_server_root: Option <PathBuf>,
|
|
|
|
|
2020-11-01 03:17:11 +00:00
|
|
|
#[structopt (long)]
|
2020-11-18 22:48:15 +00:00
|
|
|
config_path: Option <PathBuf>,
|
2020-11-18 23:24:47 +00:00
|
|
|
|
|
|
|
#[structopt (long)]
|
|
|
|
asset_root: Option <PathBuf>,
|
2020-11-24 23:56:43 +00:00
|
|
|
|
|
|
|
#[structopt (long)]
|
|
|
|
print_tripcode: bool,
|
2020-11-01 03:17:11 +00:00
|
|
|
}
|
2020-10-30 22:53:03 +00:00
|
|
|
|
2020-11-29 21:38:23 +00:00
|
|
|
fn main () -> Result <(), anyhow::Error> {
|
2020-11-18 22:48:15 +00:00
|
|
|
let opt = Opt::from_args ();
|
|
|
|
|
2020-11-06 05:03:33 +00:00
|
|
|
tracing_subscriber::fmt::init ();
|
2020-11-18 23:24:47 +00:00
|
|
|
let path = opt.config_path.clone ().unwrap_or_else (|| PathBuf::from ("./config/ptth_server.toml"));
|
2020-11-29 21:38:23 +00:00
|
|
|
let config_file: ConfigFile = load_toml::load (&path)?;
|
2020-11-06 05:03:33 +00:00
|
|
|
|
2020-11-24 23:56:43 +00:00
|
|
|
if opt.print_tripcode {
|
2020-11-30 16:15:27 +00:00
|
|
|
println! (r#"name = "{}""#, config_file.name);
|
|
|
|
println! (r#"tripcode = "{}""#, config_file.tripcode ());
|
2020-11-24 23:56:43 +00:00
|
|
|
return Ok (());
|
|
|
|
}
|
|
|
|
|
2021-03-06 21:15:41 +00:00
|
|
|
let rt = runtime::Runtime::new ()?;
|
2020-11-09 00:53:07 +00:00
|
|
|
|
2020-11-18 23:24:47 +00:00
|
|
|
rt.block_on (async move {
|
2020-11-27 00:50:22 +00:00
|
|
|
run_server (
|
2020-11-09 00:53:07 +00:00
|
|
|
config_file,
|
2020-11-27 00:03:11 +00:00
|
|
|
ptth_core::graceful_shutdown::init (),
|
2020-11-18 23:24:47 +00:00
|
|
|
Some (path),
|
|
|
|
opt.asset_root
|
2020-11-09 00:53:07 +00:00
|
|
|
).await
|
|
|
|
})?;
|
|
|
|
|
|
|
|
Ok (())
|
2020-10-30 22:53:03 +00:00
|
|
|
}
|