1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use std::fs;
use std::io;
pub fn run(s: &[String]) -> io::Result<()> {
let help = || {
println!(
"reelpath {}
https://github.com/nickgerace/reelpath
Find the absolute path of a given file or directory.
To evaluate more than one path, an additional argument per path.
Wildcards can be used in a single argument.
USAGE:
reelpath [path]...",
option_env!("CARGO_PKG_VERSION").unwrap_or("v?")
);
};
let mut print_help = false;
for i in s {
match i.as_str() {
"-h" | "-help" | "--help" => {
print_help = true;
break;
}
_ => continue,
}
}
if s.is_empty() || print_help {
help();
} else {
for i in s {
match fs::canonicalize(i) {
Ok(o) => println!("{}", o.display()),
Err(e) => return Err(e),
}
}
}
Ok(())
}