mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-02 18:55:32 +00:00
Run rustfmt, clean up aquatic_http_protocol/Cargo.toml
This commit is contained in:
parent
0cc312a78d
commit
d0e716f80b
65 changed files with 1754 additions and 2590 deletions
|
|
@ -1,43 +1,39 @@
|
|||
use aquatic_cli_helpers::{Options, run_app_with_cli_and_config, print_help};
|
||||
use aquatic_cli_helpers::{print_help, run_app_with_cli_and_config, Options};
|
||||
use aquatic_http::config::Config as HttpConfig;
|
||||
use aquatic_udp::config::Config as UdpConfig;
|
||||
use aquatic_ws::config::Config as WsConfig;
|
||||
|
||||
|
||||
#[global_allocator]
|
||||
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
|
||||
|
||||
|
||||
const APP_NAME: &str = "aquatic: BitTorrent tracker";
|
||||
|
||||
|
||||
fn main(){
|
||||
::std::process::exit(match run(){
|
||||
fn main() {
|
||||
::std::process::exit(match run() {
|
||||
Ok(()) => 0,
|
||||
Err(None) => {
|
||||
print_help(|| gen_info(), None);
|
||||
|
||||
0
|
||||
},
|
||||
Err(opt_err@Some(_)) => {
|
||||
}
|
||||
Err(opt_err @ Some(_)) => {
|
||||
print_help(|| gen_info(), opt_err);
|
||||
|
||||
1
|
||||
},
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
fn run() -> Result<(), Option<String>>{
|
||||
fn run() -> Result<(), Option<String>> {
|
||||
let mut arg_iter = ::std::env::args().skip(1);
|
||||
|
||||
let protocol = if let Some(protocol) = arg_iter.next(){
|
||||
let protocol = if let Some(protocol) = arg_iter.next() {
|
||||
protocol
|
||||
} else {
|
||||
return Err(None);
|
||||
};
|
||||
|
||||
let options = match Options::parse_args(arg_iter){
|
||||
let options = match Options::parse_args(arg_iter) {
|
||||
Ok(options) => options,
|
||||
Err(opt_err) => {
|
||||
return Err(opt_err);
|
||||
|
|
@ -45,44 +41,37 @@ fn run() -> Result<(), Option<String>>{
|
|||
};
|
||||
|
||||
match protocol.as_str() {
|
||||
"udp" => {
|
||||
run_app_with_cli_and_config::<UdpConfig>(
|
||||
aquatic_udp::APP_NAME,
|
||||
aquatic_udp::run,
|
||||
Some(options),
|
||||
)
|
||||
},
|
||||
"http" => {
|
||||
run_app_with_cli_and_config::<HttpConfig>(
|
||||
aquatic_http::APP_NAME,
|
||||
aquatic_http::run,
|
||||
Some(options),
|
||||
)
|
||||
},
|
||||
"ws" => {
|
||||
run_app_with_cli_and_config::<WsConfig>(
|
||||
aquatic_ws::APP_NAME,
|
||||
aquatic_ws::run,
|
||||
Some(options),
|
||||
)
|
||||
},
|
||||
"udp" => run_app_with_cli_and_config::<UdpConfig>(
|
||||
aquatic_udp::APP_NAME,
|
||||
aquatic_udp::run,
|
||||
Some(options),
|
||||
),
|
||||
"http" => run_app_with_cli_and_config::<HttpConfig>(
|
||||
aquatic_http::APP_NAME,
|
||||
aquatic_http::run,
|
||||
Some(options),
|
||||
),
|
||||
"ws" => run_app_with_cli_and_config::<WsConfig>(
|
||||
aquatic_ws::APP_NAME,
|
||||
aquatic_ws::run,
|
||||
Some(options),
|
||||
),
|
||||
arg => {
|
||||
let opt_err = if arg == "-h" || arg == "--help" {
|
||||
None
|
||||
} else if arg.chars().next() == Some('-'){
|
||||
} else if arg.chars().next() == Some('-') {
|
||||
Some("First argument must be protocol".to_string())
|
||||
} else {
|
||||
Some("Invalid protocol".to_string())
|
||||
};
|
||||
|
||||
return Err(opt_err)
|
||||
},
|
||||
return Err(opt_err);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
fn gen_info() -> String {
|
||||
let mut info = String::new();
|
||||
|
||||
|
|
@ -96,4 +85,4 @@ fn gen_info() -> String {
|
|||
info.push_str("\n ws WebTorrent");
|
||||
|
||||
info
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue