path-convert: improved clarity

This commit is contained in:
Valerie Wolfe 2024-05-30 15:44:02 -04:00
parent 9ab16d3b54
commit 13a73f701f

View file

@ -11,7 +11,7 @@ pub fn main() {
let next = args.subcommand().unwrap();
if let Some(arg) = next {
let mut output: String;
// resolve symlinks, etc.
// canonicalize; windows doesn't recognize symlinks
let path = Path::new(&arg).canonicalize();
if let Ok(target) = path {
output = target.to_string_lossy().to_string();
@ -19,12 +19,15 @@ pub fn main() {
output = arg;
}
// simple C-drive substitution
if output.starts_with(DRIVE) {
output = output.replace(DRIVE, "C:\\");
}
// switch out separators
output = output.replace("/", "\\");
// emit to stdout
println!("{output}");
} else {
break;