-
Notifications
You must be signed in to change notification settings - Fork 550
/
Copy pathmain.rs
43 lines (36 loc) · 1.14 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
use anyhow::Result;
use clap::Parser;
use rathole::{run, Cli};
use tokio::signal;
use tracing_subscriber::EnvFilter;
use tokio_util::sync::CancellationToken;
#[tokio::main]
async fn main() -> Result<()> {
let args = Cli::parse();
let cancel_tx = CancellationToken::new();
let cancel_rx = cancel_tx.clone();
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);
}
cancel_tx.cancel(); // synchronously
});
#[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, cancel_rx).await
}