path-convert now resolves symlinks

This commit is contained in:
Valerie Wolfe 2024-05-30 10:13:37 -04:00
parent 49d76a8bc7
commit f9c1ac5bca
3 changed files with 19 additions and 7 deletions

View file

@ -4,7 +4,7 @@ version = 3
[[package]] [[package]]
name = "path-convert" name = "path-convert"
version = "0.1.0" version = "0.0.1"
dependencies = [ dependencies = [
"pico-args", "pico-args",
] ]

View file

@ -1,6 +1,6 @@
[package] [package]
name = "path-convert" name = "path-convert"
version = "0.0.1" version = "0.0.2"
edition = "2021" edition = "2021"
[dependencies] [dependencies]

View file

@ -1,3 +1,4 @@
use std::path::Path;
use pico_args::Arguments; use pico_args::Arguments;
@ -8,12 +9,23 @@ pub fn main() {
loop { loop {
let next = args.subcommand().unwrap(); let next = args.subcommand().unwrap();
if let Some(mut arg) = next { if let Some(arg) = next {
if arg.starts_with(DRIVE) { let mut output: String;
arg = arg.replace(DRIVE, "C:\\"); // resolve symlinks, etc.
let path = Path::new(&arg).canonicalize();
if let Ok(target) = path {
output = target.to_string_lossy().to_string();
} else {
output = arg;
} }
arg = arg.replace("/", "\\");
println!("{arg}"); if output.starts_with(DRIVE) {
output = output.replace(DRIVE, "C:\\");
}
output = output.replace("/", "\\");
println!("{output}");
} else { } else {
break; break;
} }