coreutils/pwd/pwd.rs

57 lines
1.5 KiB
Rust
Raw Normal View History

2014-03-31 16:40:21 +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.
*/
2014-03-31 16:40:21 +00:00
#![feature(macro_rules)]
extern crate getopts;
extern crate libc;
2013-12-05 11:36:08 +00:00
use std::os;
use std::io::print;
2014-02-23 22:17:48 +00:00
#[path = "../common/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";
#[allow(dead_code)]
2014-05-28 11:43:37 +00:00
fn main() { uumain(os::args()); }
pub fn uumain(args: Vec<String>) {
2014-05-16 08:32:58 +00:00
let program = args.get(0).clone();
2014-05-30 08:35:54 +00:00
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!("");
2014-05-17 10:32:14 +00:00
print(getopts::usage("Print the full filename of the current working directory.", opts).as_slice());
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());
}
}