1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-31 04:57:45 +00:00

pwd: add support for -L and -P options

This commit is contained in:
Mikhail Pukhlikov 2017-09-29 17:34:21 +04:00 committed by Cynede
parent 372dda9dfa
commit f8e24439c9

View file

@ -15,6 +15,7 @@ extern crate getopts;
extern crate uucore;
use std::env;
use std::fs;
static NAME: &'static str = "pwd";
static VERSION: &'static str = env!("CARGO_PKG_VERSION");
@ -24,6 +25,8 @@ pub fn uumain(args: Vec<String>) -> i32 {
opts.optflag("", "help", "display this help and exit");
opts.optflag("", "version", "output version information and exit");
opts.optflag("L", "logical", "use PWD from environment, even if it contains symlinks");
opts.optflag("P", "physical", "avoid all symlinks");
let matches = match opts.parse(&args[1..]) {
Ok(m) => m,
@ -43,7 +46,13 @@ Print the full filename of the current working directory.", NAME, VERSION);
} else if matches.opt_present("version") {
println!("{} {}", NAME, VERSION);
} else {
println!("{}", env::current_dir().unwrap().display());
let logical_path = env::current_dir().unwrap();
if matches.opt_present("logical") {
println!("{}", logical_path.display());
} else {
let physical_path = fs::canonicalize(&logical_path);
println!("{}", physical_path.unwrap().display());
}
}
0