MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / write_and_open_html

Function write_and_open_html

atomic-cli/src/commands/triage/mod.rs:177–213  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

175/// Write the rendered HTML to a file and (unless suppressed) open it in the
176/// default browser via a `file://` URL.
177fn 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).
216fn path_to_file_url(path: &Path) -> String {

Callers 1

render_reportFunction · 0.70

Calls 6

temp_dirFunction · 0.85
path_to_file_urlFunction · 0.85
open_in_browserFunction · 0.85
writeFunction · 0.50
canonicalizeFunction · 0.50
collectMethod · 0.45

Tested by

no test coverage detected