forked from rapiz1/rathole
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
45 lines (38 loc) · 1.29 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use anyhow::Result;
use clap::Parser;
use rathole::{run, Cli};
use tokio::{signal, sync::broadcast};
use tracing_subscriber::EnvFilter;
#[tokio::main]
async fn main() -> Result<()> {
let args = Cli::parse();
let (shutdown_tx, shutdown_rx) = broadcast::channel::<bool>(1);
tokio::spawn(async move {
if let Err(e) = signal::ctrl_c().await {
// Something really weird happened. So just panic
panic!("Failed to listen for the ctrl-c signal: {:?}", e);
}
if let Err(e) = shutdown_tx.send(true) {
// shutdown signal must be catched and handle properly
// `rx` must not be dropped
panic!("Failed to send shutdown signal: {:?}", e);
}
});
#[cfg(feature = "console")]
{
console_subscriber::init();
tracing::info!("console_subscriber enabled");
}
#[cfg(not(feature = "console"))]
{
let is_atty = atty::is(atty::Stream::Stdout);
let level = "info"; // if RUST_LOG not present, use `info` level
tracing_subscriber::fmt()
.with_env_filter(
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::from(level)),
)
.with_ansi(is_atty)
.init();
}
run(args, shutdown_rx).await
}