-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.rs
More file actions
84 lines (75 loc) · 2.57 KB
/
main.rs
File metadata and controls
84 lines (75 loc) · 2.57 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
use clap::Parser;
use dotenvy::dotenv;
use stackable_cockpit::PROGRESS_SPINNER_STYLE;
use stackablectl::cli::{Cli, Error};
use tracing::{Level, metadata::LevelFilter};
use tracing_indicatif::{
IndicatifLayer,
filter::{IndicatifFilter, hide_indicatif_span_fields},
indicatif_eprintln, indicatif_println,
};
use tracing_subscriber::{
Layer as _,
fmt::{self, format::DefaultFields},
layer::SubscriberExt,
util::SubscriberInitExt,
};
#[snafu::report]
#[tokio::main]
async fn main() -> Result<(), Error> {
// Parse the CLI args and commands
let cli = Cli::parse();
// As stackable-operator pulls in ring and reqwest >= 0.13 pulls in aws_lc_rs, we need
// to explicitly tell rustls what provider to use. As other operators use ring, we use
// that for consistency reasons here as well.
rustls::crypto::ring::default_provider()
.install_default()
.expect("failed to install ring rustls provider");
// Construct the tracing subscriber
let format = fmt::format()
.with_ansi(true)
.without_time()
.with_target(false);
let indicatif_layer = IndicatifLayer::new()
.with_span_field_formatter(
// If the `{span_fields}` interpolation is used in a template, then we want to hide the
// indicatif control fields "indicatif.pb_show" and "indicatif.pb_hide"
hide_indicatif_span_fields(DefaultFields::new()),
)
.with_progress_style(PROGRESS_SPINNER_STYLE.clone());
if let Some(level) = cli.log_level {
tracing_subscriber::registry()
.with(
fmt::layer()
.event_format(format)
.pretty()
.with_writer(indicatif_layer.get_stderr_writer()),
)
.with(LevelFilter::from_level(level))
.init();
} else {
tracing_subscriber::registry()
.with(LevelFilter::from_level(Level::INFO))
.with(indicatif_layer.with_filter(IndicatifFilter::new(false)))
.init();
}
// Load env vars from optional .env file
match dotenv() {
Ok(_) => (),
Err(err) => {
if !err.not_found() {
indicatif_eprintln!("{err}")
}
}
}
match cli.run().await {
Ok(result) => indicatif_println!("{result}"),
Err(err) => {
let mut output = Cli::error();
output.with_error_report(err);
indicatif_eprintln!("{error}", error = output.render());
std::process::exit(1);
}
}
Ok(())
}