coreutils/pwd/pwd.rs

55 lines
1.4 KiB
Rust
Raw Normal View History

2013-12-26 10:49:31 +00:00
#[crate_id(name="pwd", vers="1.0.0", author="Heather Cynede")];
2013-12-05 11:36:08 +00:00
/*
* 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.
*/
#[feature(macro_rules)];
2013-12-05 11:36:08 +00:00
extern mod extra;
extern mod getopts;
2013-12-05 11:36:08 +00:00
use std::os;
use std::io::print;
#[path = "../util.rs"]
mod util;
2013-12-05 11:36:08 +00:00
static NAME: &'static str = "pwd";
2013-12-05 11:36:08 +00:00
static VERSION: &'static str = "1.0.0";
fn main() {
let args = os::args();
let program = args[0].clone();
let opts = ~[
getopts::optflag("", "help", "display this help and exit"),
getopts::optflag("", "version", "output version information and exit"),
2013-12-05 11:36:08 +00:00
];
let matches = match getopts::getopts(args.tail(), opts) {
2013-12-05 11:36:08 +00:00
Ok(m) => m,
Err(f) => {
crash!(1, "Invalid options\n{}", f.to_err_msg())
}
2013-12-05 11:36:08 +00:00
};
if matches.opt_present("help") {
println!("pwd {}", VERSION);
println!("");
println!("Usage:");
2013-12-05 11:36:08 +00:00
println!(" {0:s} [OPTION] NAME...", program);
println!("");
print(getopts::usage("Print the full filename of the current working directory.", opts));
2013-12-05 11:36:08 +00:00
} else if matches.opt_present("version") {
return println!("pwd version: {}", VERSION);
2013-12-05 11:36:08 +00:00
} else {
let cwd = std::os::getcwd();
println!("{}", cwd.display());
}
}