mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-28 02:18:50 +00:00
fixes #2651 Wip because firezone portal doesn't handle names longer than 8 characters yet cc @AndrewDryga
44 lines
1.4 KiB
Rust
44 lines
1.4 KiB
Rust
use clap::Args;
|
|
use tracing_log::LogTracer;
|
|
use tracing_subscriber::{
|
|
fmt, prelude::__tracing_subscriber_SubscriberExt, EnvFilter, Layer, Registry,
|
|
};
|
|
use url::Url;
|
|
|
|
pub fn block_on_ctrl_c() {
|
|
let (tx, rx) = std::sync::mpsc::channel();
|
|
ctrlc::set_handler(move || tx.send(()).expect("Could not send stop signal on channel."))
|
|
.expect("Error setting Ctrl-C handler");
|
|
rx.recv().expect("Could not receive ctrl-c signal");
|
|
}
|
|
|
|
pub fn setup_global_subscriber<L>(additional_layer: L)
|
|
where
|
|
L: Layer<Registry> + Send + Sync,
|
|
{
|
|
let subscriber = Registry::default()
|
|
.with(additional_layer.with_filter(EnvFilter::from_default_env()))
|
|
.with(fmt::layer().with_filter(EnvFilter::from_default_env()));
|
|
tracing::subscriber::set_global_default(subscriber).expect("Could not set global default");
|
|
LogTracer::init().unwrap();
|
|
}
|
|
|
|
/// Arguments common to all Firezone CLI components.
|
|
#[derive(Args, Clone)]
|
|
pub struct CommonArgs {
|
|
#[arg(
|
|
short = 'u',
|
|
long,
|
|
hide = true,
|
|
env = "FIREZONE_API_URL",
|
|
default_value = "wss://api.firezone.dev"
|
|
)]
|
|
pub api_url: Url,
|
|
/// Token generated by the portal to authorize websocket connection.
|
|
#[arg(env = "FIREZONE_TOKEN")]
|
|
pub token: String,
|
|
/// Friendly name to display in the UI
|
|
#[arg(short = 'n', long, env = "FIREZONE_NAME")]
|
|
pub firezone_name: Option<String>,
|
|
}
|