MCPcopy Create free account
hub / github.com/aws/amazon-q-developer-cli / format_path

Function format_path

crates/chat-cli/src/cli/chat/tools/mod.rs:432–445  ·  view source on GitHub ↗

Small helper for formatting the path as a relative path, if able.

(cwd: impl AsRef<Path>, path: impl AsRef<Path>)

Source from the content-addressed store, hash-verified

430
431/// Small helper for formatting the path as a relative path, if able.
432fn format_path(cwd: impl AsRef<Path>, path: impl AsRef<Path>) -> String {
433 absolute_to_relative(cwd, path.as_ref())
434 .map(|p| p.to_string_lossy().to_string())
435 // If we have three consecutive ".." then it should probably just stay as an absolute path.
436 .map(|p| {
437 let three_up = format!("..{}..{}..", std::path::MAIN_SEPARATOR, std::path::MAIN_SEPARATOR);
438 if p.starts_with(&three_up) {
439 path.as_ref().to_string_lossy().to_string()
440 } else {
441 p
442 }
443 })
444 .unwrap_or(path.as_ref().to_string_lossy().to_string())
445}
446
447fn supports_truecolor() -> bool {
448 // Simple override to disable truecolor since shell_color doesn't use Context.

Callers 4

assert_pathsFunction · 0.85
queue_descriptionMethod · 0.85
print_relative_pathMethod · 0.85
validateMethod · 0.85

Calls 4

absolute_to_relativeFunction · 0.85
mapMethod · 0.80
to_stringMethod · 0.80
as_refMethod · 0.45

Tested by

no test coverage detected