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

Function display_path

atomic-cli/src/commands/diagnostics/collect.rs:1366–1386  ·  view source on GitHub ↗

`path` with the home directory shown as `~`, so a pasted report does not carry the user's account name. The part after `~` is joined with `/` on every platform, so Windows never renders a mixed `~/.x\settings.json`.

(path: &Path, home: Option<&Path>)

Source from the content-addressed store, hash-verified

1364/// carry the user's account name. The part after `~` is joined with `/` on
1365/// every platform, so Windows never renders a mixed `~/.x\settings.json`.
1366fn display_path(path: &Path, home: Option<&Path>) -> String {
1367 let canonical_home = home.and_then(|home| home.canonicalize().ok());
1368 let relative = home
1369 .and_then(|home| path.strip_prefix(home).ok())
1370 .or_else(|| {
1371 canonical_home
1372 .as_deref()
1373 .and_then(|home| path.strip_prefix(home).ok())
1374 });
1375 match relative {
1376 Some(rest) if rest.as_os_str().is_empty() => "~".to_string(),
1377 Some(rest) => {
1378 let parts: Vec<_> = rest
1379 .components()
1380 .map(|part| part.as_os_str().to_string_lossy())
1381 .collect();
1382 format!("~/{}", parts.join("/"))
1383 }
1384 None => path.display().to_string(),
1385 }
1386}
1387
1388#[cfg(test)]
1389mod tests {

Callers 3

collect_fromFunction · 0.70
describe_sourceFunction · 0.70
collect_git_shimFunction · 0.70

Calls 6

canonicalizeMethod · 0.80
componentsMethod · 0.80
displayMethod · 0.80
okMethod · 0.45
is_emptyMethod · 0.45
collectMethod · 0.45

Tested by

no test coverage detected