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]]
name = "path-convert"
version = "0.1.0"
version = "0.0.1"
dependencies = [
"pico-args",
]

View file

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

View file

@ -1,3 +1,4 @@
use std::path::Path;
use pico_args::Arguments;
@ -8,12 +9,23 @@ pub fn main() {
loop {
let next = args.subcommand().unwrap();
if let Some(mut arg) = next {
if arg.starts_with(DRIVE) {
arg = arg.replace(DRIVE, "C:\\");
if let Some(arg) = next {
let mut output: String;
// 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 {
break;
}