mirror of
https://github.com/uutils/coreutils
synced 2024-12-13 14:52:41 +00:00
simple pwd implementation
This commit is contained in:
parent
80f300a0ea
commit
a007dadeda
3 changed files with 52 additions and 1 deletions
1
Makefile
1
Makefile
|
@ -14,6 +14,7 @@ EXES := \
|
|||
env \
|
||||
false \
|
||||
printenv \
|
||||
pwd \
|
||||
true \
|
||||
wc \
|
||||
whoami \
|
||||
|
|
|
@ -98,7 +98,6 @@ To do
|
|||
- printf
|
||||
- prog-fprintf
|
||||
- ptx
|
||||
- pwd
|
||||
- readlink
|
||||
- realpath
|
||||
- relpath
|
||||
|
|
51
pwd/pwd.rs
Normal file
51
pwd/pwd.rs
Normal file
|
@ -0,0 +1,51 @@
|
|||
#[link(name="pwd", vers="1.0.0", author="Heather Cynede")];
|
||||
|
||||
/*
|
||||
* This file is part of the uutils coreutils package.
|
||||
*
|
||||
* (c) Derek Chiang <derekchiang93@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
extern mod extra;
|
||||
|
||||
use std::os;
|
||||
use std::io::stderr;
|
||||
use extra::getopts::groups;
|
||||
|
||||
static VERSION: &'static str = "1.0.0";
|
||||
|
||||
fn main() {
|
||||
let args = os::args();
|
||||
let program = args[0].clone();
|
||||
let opts = ~[
|
||||
groups::optflag("", "help", "display this help and exit"),
|
||||
groups::optflag("", "version", "output version information and exit"),
|
||||
];
|
||||
|
||||
let matches = match groups::getopts(args.tail(), opts) {
|
||||
Ok(m) => m,
|
||||
Err(f) => {
|
||||
writeln!(&mut stderr() as &mut Writer,
|
||||
"Invalid options\n{}", f.to_err_msg());
|
||||
os::set_exit_status(1);
|
||||
return
|
||||
}
|
||||
};
|
||||
|
||||
if matches.opt_present("help") {
|
||||
println!("pwd {}", VERSION);
|
||||
println("");
|
||||
println("Usage:");
|
||||
println!(" {0:s} [OPTION] NAME...", program);
|
||||
println("");
|
||||
print(groups::usage("Print the full filename of the current working directory.", opts));
|
||||
} else if matches.opt_present("version") {
|
||||
return println("pwd version: " + VERSION);
|
||||
} else {
|
||||
let cwd = std::os::getcwd();
|
||||
println!("{}", cwd.display());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue