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:129–165  ·  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

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

Callers 1

runMethod · 0.85

Calls 5

temp_dirFunction · 0.85
writeFunction · 0.85
canonicalizeFunction · 0.85
path_to_file_urlFunction · 0.85
open_in_browserFunction · 0.85

Tested by

no test coverage detected