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:130–166  ·  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

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