52 lines
1.5 KiB
Rust
52 lines
1.5 KiB
Rust
use std::{
|
|
iter::FromIterator,
|
|
};
|
|
|
|
enum Subcommand {
|
|
PtthServer,
|
|
PtthQuicEndServer,
|
|
}
|
|
|
|
fn parse_subcommand (name: &str) -> Option <Subcommand>
|
|
{
|
|
if name.ends_with ("ptth_server") || name.ends_with ("ptth_server.exe")
|
|
{
|
|
Some (Subcommand::PtthServer)
|
|
}
|
|
else if name.ends_with ("ptth_quic_end_server") || name.ends_with ("ptth_quic_end_server.exe")
|
|
{
|
|
Some (Subcommand::PtthQuicEndServer)
|
|
}
|
|
else {
|
|
None
|
|
}
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main () -> anyhow::Result <()> {
|
|
tracing_subscriber::fmt::init ();
|
|
|
|
let args = Vec::from_iter (std::env::args_os ());
|
|
|
|
let arg_0 = args [0].to_str ().expect ("exe name should be valid UTF-8");
|
|
match parse_subcommand (arg_0) {
|
|
Some (Subcommand::PtthServer) => return ptth_server::executable::main (&args).await,
|
|
Some (Subcommand::PtthQuicEndServer) => return quic_demo::executable_end_server::main (&args).await,
|
|
_ => (),
|
|
}
|
|
|
|
let arg_1 = match args.get (1) {
|
|
Some (x) => x,
|
|
None => anyhow::bail! ("Subcommand must be the first argument if it's not the exe name"),
|
|
};
|
|
|
|
let arg_1 = arg_1.to_str ().expect ("subcommand should be valid UTF-8");
|
|
match parse_subcommand (arg_1) {
|
|
Some (Subcommand::PtthServer) => return ptth_server::executable::main (&args [1..]).await,
|
|
Some (Subcommand::PtthQuicEndServer) => return quic_demo::executable_end_server::main (&args [1..]).await,
|
|
_ => (),
|
|
}
|
|
|
|
anyhow::bail! ("Subcommand should be provided in exe name or first argument, e.g. `./ptth_multi_call_server ptth_server`");
|
|
}
|