path-convert now resolves symlinks
This commit is contained in:
parent
49d76a8bc7
commit
f9c1ac5bca
3 changed files with 19 additions and 7 deletions
2
path-convert/Cargo.lock
generated
2
path-convert/Cargo.lock
generated
|
@ -4,7 +4,7 @@ version = 3
|
|||
|
||||
[[package]]
|
||||
name = "path-convert"
|
||||
version = "0.1.0"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"pico-args",
|
||||
]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "path-convert"
|
||||
version = "0.0.1"
|
||||
version = "0.0.2"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue