mirror of
https://github.com/uutils/coreutils
synced 2024-12-14 23:32:39 +00:00
30bba07f9c
squashed: a2c6b27 - build: automatically generate main() files c942f0f - remove MULTICALL=1 build from travis cb7b35b - make: remove unnecessary shell command 69bbb31 - update README 03a3168 - all: move main() into separate file that links against util crate 8276384 - make: always build multicall binary aa4edeb - make: avoid 'rustc --crate-file-name'
63 lines
1.6 KiB
Rust
63 lines
1.6 KiB
Rust
#![crate_id(name="link", vers="1.0.0", author="Michael Gehring")]
|
|
#![feature(macro_rules)]
|
|
|
|
/*
|
|
* This file is part of the uutils coreutils package.
|
|
*
|
|
* (c) Michael Gehring <mg@ebfe.org>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
extern crate getopts;
|
|
|
|
use std::io::fs::link;
|
|
use std::path::Path;
|
|
|
|
#[path="../common/util.rs"]
|
|
mod util;
|
|
|
|
static NAME : &'static str = "link";
|
|
static VERSION : &'static str = "1.0.0";
|
|
|
|
pub fn uumain(args: Vec<String>) -> int {
|
|
let opts = [
|
|
getopts::optflag("h", "help", "display this help and exit"),
|
|
getopts::optflag("V", "version", "output version information and exit"),
|
|
];
|
|
|
|
let matches = match getopts::getopts(args.tail(), opts) {
|
|
Ok(m) => m,
|
|
Err(err) => fail!("{}", err),
|
|
};
|
|
|
|
if matches.opt_present("version") {
|
|
println!("{} {}", NAME, VERSION);
|
|
return 0;
|
|
}
|
|
|
|
if matches.opt_present("help") || matches.free.len() != 2 {
|
|
println!("{} {}", NAME, VERSION);
|
|
println!("");
|
|
println!("Usage:");
|
|
println!(" {} [OPTIONS] FILE1 FILE2", NAME);
|
|
println!("");
|
|
print!("{}", getopts::usage("Create a link named FILE2 to FILE1.", opts.as_slice()).as_slice());
|
|
if matches.free.len() != 2 {
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
let old = Path::new(matches.free.get(0).as_slice());
|
|
let new = Path::new(matches.free.get(1).as_slice());
|
|
|
|
match link(&old, &new) {
|
|
Ok(_) => 0,
|
|
Err(err) => {
|
|
show_error!("{}", err);
|
|
1
|
|
}
|
|
}
|
|
}
|