Skip to content

Commit 232be86

Browse files
committed
Add a helper function for outputting details
1 parent 634a11e commit 232be86

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

src/ci/citool/src/analysis.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::metrics;
22
use crate::metrics::{JobMetrics, JobName, get_test_suites};
3-
use crate::utils::pluralize;
3+
use crate::utils::{output_details, pluralize};
44
use build_helper::metrics::{
55
BuildStep, JsonRoot, TestOutcome, TestSuite, TestSuiteMetadata, format_build_steps,
66
};
@@ -19,14 +19,9 @@ fn record_bootstrap_step_durations(metrics: &JsonRoot) {
1919
let step = BuildStep::from_invocation(invocation);
2020
let table = format_build_steps(&step);
2121
eprintln!("Step `{}`\n{table}\n", invocation.cmdline);
22-
println!(
23-
r"<details>
24-
<summary>{}</summary>
25-
<pre><code>{table}</code></pre>
26-
</details>
27-
",
28-
invocation.cmdline
29-
);
22+
output_details(&invocation.cmdline, || {
23+
println!("<pre><code>{table}</code></pre>");
24+
});
3025
}
3126
eprintln!("Recorded {} bootstrap invocation(s)", metrics.invocations.len());
3227
}

src/ci/citool/src/utils.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,17 @@ pub fn read_to_string<P: AsRef<Path>>(path: P) -> anyhow::Result<String> {
1313
pub fn pluralize(text: &str, count: usize) -> String {
1414
if count == 1 { text.to_string() } else { format!("{text}s") }
1515
}
16+
17+
/// Outputs a HTML <details> section with the provided summary.
18+
/// Output printed by `func` will be contained within the section.
19+
pub fn output_details<F>(summary: &str, func: F)
20+
where
21+
F: FnOnce(),
22+
{
23+
println!(
24+
r"<details>
25+
<summary>{summary}</summary>"
26+
);
27+
func();
28+
println!("</details>\n");
29+
}

0 commit comments

Comments
 (0)