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,
)
| 127 | /// Write the rendered HTML to a file and (unless suppressed) open it in the |
| 128 | /// default browser via a `file://` URL. |
| 129 | fn write_and_open_html( |
| 130 | html: &str, |
| 131 | report: &model::TriageReport, |
| 132 | output: Option<&Path>, |
| 133 | open: bool, |
| 134 | ) -> CliResult<()> { |
| 135 | let path: PathBuf = match output { |
| 136 | Some(p) => p.to_path_buf(), |
| 137 | None => { |
| 138 | let slug = |s: &str| -> String { |
| 139 | s.chars() |
| 140 | .map(|c| if c.is_ascii_alphanumeric() { c } else { '-' }) |
| 141 | .collect() |
| 142 | }; |
| 143 | std::env::temp_dir().join(format!( |
| 144 | "atomic-triage-{}-into-{}.html", |
| 145 | slug(&report.inputs.feature), |
| 146 | slug(&report.inputs.target), |
| 147 | )) |
| 148 | } |
| 149 | }; |
| 150 | |
| 151 | std::fs::write(&path, html)?; |
| 152 | let abs = std::fs::canonicalize(&path).unwrap_or(path); |
| 153 | let url = path_to_file_url(&abs); |
| 154 | |
| 155 | println!("Wrote triage report to {}", abs.display()); |
| 156 | println!("{}", url); |
| 157 | |
| 158 | if open { |
| 159 | if let Err(e) = open_in_browser(&url) { |
| 160 | eprintln!("(could not open a browser: {e} — open the file:// URL above manually)"); |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | Ok(()) |
| 165 | } |
| 166 | |
| 167 | /// Convert an absolute filesystem path into a `file://` URL (spaces encoded). |
| 168 | fn path_to_file_url(path: &Path) -> String { |
no test coverage detected