♻️ refactor: clean up `.exe` handling and add a place for `ptth_file_server`
parent
4329562aa3
commit
4c79af3f4b
|
@ -3,25 +3,32 @@ use std::{
|
|||
iter::FromIterator,
|
||||
};
|
||||
|
||||
#[derive (Debug, PartialEq)]
|
||||
#[derive (Clone, Copy, Debug, PartialEq)]
|
||||
enum Subcommand {
|
||||
PtthServer,
|
||||
PtthFileServer,
|
||||
PtthQuicEndServer,
|
||||
}
|
||||
|
||||
fn parse_subcommand (name: &str) -> Option <Subcommand>
|
||||
fn parse_subcommand (arg: &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
|
||||
use Subcommand::*;
|
||||
|
||||
let map = vec! [
|
||||
("ptth_server", PtthServer),
|
||||
("ptth_file_server", PtthFileServer),
|
||||
("ptth_quic_end_server", PtthQuicEndServer),
|
||||
];
|
||||
|
||||
let arg = arg.strip_suffix (".exe").unwrap_or (arg);
|
||||
|
||||
for (suffix, subcommand) in &map {
|
||||
if arg.ends_with (suffix) {
|
||||
return Some (*subcommand);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
fn parse_args (args: &[OsString]) -> anyhow::Result <(Subcommand, &[OsString])>
|
||||
|
@ -60,6 +67,7 @@ async fn main () -> anyhow::Result <()> {
|
|||
let (subcommand, args) = parse_args (&args)?;
|
||||
match subcommand {
|
||||
Subcommand::PtthServer => ptth_server::executable::main (&args).await,
|
||||
Subcommand::PtthFileServer => unimplemented! (),
|
||||
Subcommand::PtthQuicEndServer => quic_demo::executable_end_server::main (&args).await,
|
||||
}
|
||||
}
|
||||
|
@ -74,6 +82,7 @@ mod tests {
|
|||
vec! [],
|
||||
vec! ["invalid_exe_name"],
|
||||
vec! ["ptth_multi_call_server"],
|
||||
vec! ["ptth_server.ex"],
|
||||
vec! ["ptth_multi_call_server", "invalid_subcommand"],
|
||||
];
|
||||
|
||||
|
@ -85,8 +94,10 @@ mod tests {
|
|||
}
|
||||
|
||||
let positive_cases = vec! [
|
||||
(vec! ["ptth_server.exe"], (Subcommand::PtthServer, vec! ["ptth_server.exe"])),
|
||||
(vec! ["ptth_server"], (Subcommand::PtthServer, vec! ["ptth_server"])),
|
||||
(vec! ["ptth_server", "--help"], (Subcommand::PtthServer, vec! ["ptth_server", "--help"])),
|
||||
(vec! ["ptth_file_server"], (Subcommand::PtthFileServer, vec! ["ptth_file_server"])),
|
||||
(vec! ["ptth_quic_end_server", "--help"], (Subcommand::PtthQuicEndServer, vec! ["ptth_quic_end_server", "--help"])),
|
||||
(vec! ["ptth_multi_call_server", "ptth_server"], (Subcommand::PtthServer, vec! ["ptth_server"])),
|
||||
(
|
||||
|
|
Loading…
Reference in New Issue