add `--name` so caller program can provide name
parent
13c1ddc01a
commit
56496bf97b
|
@ -8,7 +8,6 @@ use structopt::StructOpt;
|
||||||
use tokio::runtime;
|
use tokio::runtime;
|
||||||
|
|
||||||
use ptth_server::{
|
use ptth_server::{
|
||||||
ConfigFile,
|
|
||||||
load_toml,
|
load_toml,
|
||||||
run_server,
|
run_server,
|
||||||
};
|
};
|
||||||
|
@ -18,23 +17,46 @@ struct Opt {
|
||||||
//#[structopt (long)]
|
//#[structopt (long)]
|
||||||
//file_server_root: Option <PathBuf>,
|
//file_server_root: Option <PathBuf>,
|
||||||
|
|
||||||
#[structopt (long)]
|
|
||||||
config_path: Option <PathBuf>,
|
|
||||||
|
|
||||||
#[structopt (long)]
|
#[structopt (long)]
|
||||||
asset_root: Option <PathBuf>,
|
asset_root: Option <PathBuf>,
|
||||||
|
|
||||||
|
#[structopt (long)]
|
||||||
|
config_path: Option <PathBuf>,
|
||||||
|
|
||||||
|
#[structopt (long)]
|
||||||
|
name: Option <String>,
|
||||||
|
|
||||||
#[structopt (long)]
|
#[structopt (long)]
|
||||||
print_tripcode: bool,
|
print_tripcode: bool,
|
||||||
|
|
||||||
|
#[structopt (long)]
|
||||||
|
relay_url: Option <String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive (Default, serde::Deserialize)]
|
||||||
|
pub struct ConfigFile {
|
||||||
|
pub name: Option <String>,
|
||||||
|
pub api_key: String,
|
||||||
|
pub relay_url: Option <String>,
|
||||||
|
pub file_server_root: Option <PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main () -> Result <(), anyhow::Error> {
|
fn main () -> Result <(), anyhow::Error> {
|
||||||
let opt = Opt::from_args ();
|
|
||||||
|
|
||||||
tracing_subscriber::fmt::init ();
|
tracing_subscriber::fmt::init ();
|
||||||
|
|
||||||
|
let opt = Opt::from_args ();
|
||||||
|
let asset_root = opt.asset_root;
|
||||||
|
|
||||||
let path = opt.config_path.clone ().unwrap_or_else (|| PathBuf::from ("./config/ptth_server.toml"));
|
let path = opt.config_path.clone ().unwrap_or_else (|| PathBuf::from ("./config/ptth_server.toml"));
|
||||||
let config_file: ConfigFile = load_toml::load (&path)?;
|
let config_file: ConfigFile = load_toml::load (&path)?;
|
||||||
|
|
||||||
|
let config_file = ptth_server::ConfigFile {
|
||||||
|
name: opt.name.or (config_file.name).expect ("`name` must be provided in command line or config file"),
|
||||||
|
api_key: config_file.api_key,
|
||||||
|
relay_url: opt.relay_url.or (config_file.relay_url).expect ("`relay_url` must be provided in command line of config file"),
|
||||||
|
file_server_root: config_file.file_server_root,
|
||||||
|
};
|
||||||
|
|
||||||
if opt.print_tripcode {
|
if opt.print_tripcode {
|
||||||
println! (r#"name = "{}""#, config_file.name);
|
println! (r#"name = "{}""#, config_file.name);
|
||||||
println! (r#"tripcode = "{}""#, config_file.tripcode ());
|
println! (r#"tripcode = "{}""#, config_file.tripcode ());
|
||||||
|
@ -48,7 +70,7 @@ fn main () -> Result <(), anyhow::Error> {
|
||||||
config_file,
|
config_file,
|
||||||
ptth_core::graceful_shutdown::init (),
|
ptth_core::graceful_shutdown::init (),
|
||||||
Some (path),
|
Some (path),
|
||||||
opt.asset_root
|
asset_root
|
||||||
).await
|
).await
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,6 @@ use std::{
|
||||||
|
|
||||||
use futures::FutureExt;
|
use futures::FutureExt;
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use serde::Deserialize;
|
|
||||||
use tokio::{
|
use tokio::{
|
||||||
sync::{
|
sync::{
|
||||||
oneshot,
|
oneshot,
|
||||||
|
@ -146,7 +145,11 @@ async fn handle_req_resp (
|
||||||
Ok (())
|
Ok (())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive (Default, Deserialize)]
|
// A complete config file. The bin frontend is allowed to use a different
|
||||||
|
// type to load an incomplete file, as long as the command line options
|
||||||
|
// complete it.
|
||||||
|
|
||||||
|
#[derive (Default)]
|
||||||
pub struct ConfigFile {
|
pub struct ConfigFile {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub api_key: String,
|
pub api_key: String,
|
||||||
|
|
Loading…
Reference in New Issue