ptth/src/bin/server.rs

38 lines
871 B
Rust

use std::{
error::Error,
path::PathBuf,
};
use structopt::StructOpt;
#[derive (Debug, StructOpt)]
struct Opt {
#[structopt (name = "RELAY_URL")]
relay_url: String,
#[structopt (long)]
file_server_root: Option <PathBuf>,
}
#[tokio::main]
async fn main () -> Result <(), Box <dyn Error>> {
use std::io::Read;
let mut f = std::fs::File::open ("ptth_server.toml").unwrap ();
let mut buffer = vec! [0u8; 4096];
let bytes_read = f.read (&mut buffer).unwrap ();
buffer.truncate (bytes_read);
let config_s = String::from_utf8 (buffer).unwrap ();
let config_file: ptth::server::ConfigFile = toml::from_str (&config_s).unwrap ();
let opt = Opt::from_args ();
let opt = ptth::server::Opt {
relay_url: opt.relay_url,
file_server_root: opt.file_server_root.unwrap_or_else (|| "/home/user".into ()),
};
ptth::server::main (config_file, opt).await
}