ptth/crates/ptth_server/src/bin/ptth_server.rs

57 lines
1.0 KiB
Rust
Raw Normal View History

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