Write the rendered HTML to a file and (unless suppressed) open it in the default browser via a `file://` URL.
(
html: &str,
report: &model::TriageReport,
output: Option<&Path>,
open: bool,
)
| 175 | /// Write the rendered HTML to a file and (unless suppressed) open it in the |
| 176 | /// default browser via a `file://` URL. |
| 177 | fn write_and_open_html( |
| 178 | html: &str, |
| 179 | report: &model::TriageReport, |
| 180 | output: Option<&Path>, |
| 181 | open: bool, |
| 182 | ) -> CliResult<()> { |
| 183 | let path: PathBuf = match output { |
| 184 | Some(p) => p.to_path_buf(), |
| 185 | None => { |
| 186 | let slug = |s: &str| -> String { |
| 187 | s.chars() |
| 188 | .map(|c| if c.is_ascii_alphanumeric() { c } else { '-' }) |
| 189 | .collect() |
| 190 | }; |
| 191 | std::env::temp_dir().join(format!( |
| 192 | "atomic-triage-{}-into-{}.html", |
| 193 | slug(&report.inputs.feature), |
| 194 | slug(&report.inputs.target), |
| 195 | )) |
| 196 | } |
| 197 | }; |
| 198 | |
| 199 | std::fs::write(&path, html)?; |
| 200 | let abs = std::fs::canonicalize(&path).unwrap_or(path); |
| 201 | let url = path_to_file_url(&abs); |
| 202 | |
| 203 | println!("Wrote triage report to {}", abs.display()); |
| 204 | println!("{}", url); |
| 205 | |
| 206 | if open { |
| 207 | if let Err(e) = open_in_browser(&url) { |
| 208 | eprintln!("(could not open a browser: {e} — open the file:// URL above manually)"); |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | Ok(()) |
| 213 | } |
| 214 | |
| 215 | /// Convert an absolute filesystem path into a `file://` URL (spaces encoded). |
| 216 | fn path_to_file_url(path: &Path) -> String { |
no test coverage detected