Skip to content

Commit 487df5a

Browse files
committed
chore: Make progress bar template reusable through a LazyLock
1 parent ed760d5 commit 487df5a

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

rust/stackable-cockpit/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
use std::sync::LazyLock;
2+
3+
use indicatif::ProgressStyle;
4+
15
pub mod common;
26
pub mod constants;
37
pub mod engine;
@@ -6,3 +10,10 @@ pub mod oci;
610
pub mod platform;
711
pub mod utils;
812
pub mod xfer;
13+
14+
pub(crate) static PROGRESS_BAR_STYLE: LazyLock<ProgressStyle> = LazyLock::new(|| {
15+
ProgressStyle::with_template(
16+
"{span_child_prefix} Progress {msg}: {wide_bar:.magenta/cyan} {pos}/{len}",
17+
)
18+
.expect("valid progress template")
19+
});

rust/stackable-cockpit/src/platform/manifests.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use tracing::{Instrument as _, Span, debug, info, info_span, instrument};
77
use tracing_indicatif::span_ext::IndicatifSpanExt as _;
88

99
use crate::{
10+
PROGRESS_BAR_STYLE,
1011
common::manifest::ManifestSpec,
1112
helm,
1213
utils::{
@@ -76,10 +77,7 @@ pub trait InstallManifestsExt {
7677
) -> Result<(), Error> {
7778
debug!("Installing manifests");
7879

79-
Span::current().pb_set_style(
80-
&ProgressStyle::with_template("Progress: {wide_bar} {pos}/{len}")
81-
.expect("valid progress template"),
82-
);
80+
Span::current().pb_set_style(&PROGRESS_BAR_STYLE);
8381
Span::current().pb_set_length(manifests.len() as u64);
8482

8583
let mut parameters = parameters.clone();

rust/stackable-cockpit/src/platform/release/spec.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use futures::{StreamExt as _, TryStreamExt};
22
use indexmap::IndexMap;
3-
use indicatif::ProgressStyle;
43
use serde::{Deserialize, Serialize};
54
use snafu::{ResultExt, Snafu};
65
use tokio::task::JoinError;
@@ -10,7 +9,7 @@ use tracing_indicatif::span_ext::IndicatifSpanExt as _;
109
use utoipa::ToSchema;
1110

1211
use crate::{
13-
helm,
12+
PROGRESS_BAR_STYLE, helm,
1413
platform::{
1514
operator::{self, ChartSourceType, OperatorSpec},
1615
product,
@@ -64,10 +63,7 @@ impl ReleaseSpec {
6463
chart_source: &ChartSourceType,
6564
) -> Result<()> {
6665
info!("Installing release");
67-
Span::current().pb_set_style(
68-
&ProgressStyle::with_template("Progress: {wide_bar} {pos}/{len}")
69-
.expect("valid progress template"),
70-
);
66+
Span::current().pb_set_style(&PROGRESS_BAR_STYLE);
7167

7268
include_products.iter().for_each(|product| {
7369
Span::current().record("product.included", product);
@@ -125,10 +121,7 @@ impl ReleaseSpec {
125121
pub fn uninstall(&self, namespace: &str) -> Result<()> {
126122
info!("Uninstalling release");
127123

128-
Span::current().pb_set_style(
129-
&ProgressStyle::with_template("Progress: {wide_bar} {pos}/{len}")
130-
.expect("valid progress template"),
131-
);
124+
Span::current().pb_set_style(&PROGRESS_BAR_STYLE);
132125
Span::current().pb_set_length(self.products.len() as u64);
133126

134127
for (product_name, product_spec) in &self.products {

0 commit comments

Comments
 (0)