mirror of
https://github.com/uutils/coreutils
synced 2024-07-22 02:14:38 +00:00
commit
70c6fb0887
|
@ -16,6 +16,7 @@ extern crate getopts;
|
|||
extern crate libc;
|
||||
|
||||
use std::io::print;
|
||||
use std::borrow::IntoCow;
|
||||
|
||||
#[path = "../common/util.rs"]
|
||||
#[macro_use]
|
||||
|
@ -24,7 +25,7 @@ mod util;
|
|||
static NAME: &'static str = "yes";
|
||||
|
||||
pub fn uumain(args: Vec<String>) -> isize {
|
||||
let program = args[0].clone();
|
||||
let program = &args[0];
|
||||
let opts = [
|
||||
getopts::optflag("h", "help", "display this help and exit"),
|
||||
getopts::optflag("V", "version", "output version information and exit"),
|
||||
|
@ -41,27 +42,24 @@ pub fn uumain(args: Vec<String>) -> isize {
|
|||
println!("Usage:");
|
||||
println!(" {0} [STRING]... [OPTION]...", program);
|
||||
println!("");
|
||||
print(getopts::usage("Repeatedly output a line with all specified STRING(s), or 'y'.", &opts).as_slice());
|
||||
print(&getopts::usage("Repeatedly output a line with all specified STRING(s), or 'y'.", &opts)[]);
|
||||
return 0;
|
||||
}
|
||||
if matches.opt_present("version") {
|
||||
println!("yes 1.0.0");
|
||||
return 0;
|
||||
}
|
||||
let mut string = "y".to_string();
|
||||
if !matches.free.is_empty() {
|
||||
string = matches.free.connect(" ");
|
||||
}
|
||||
let string = if matches.free.is_empty() {
|
||||
"y".into_cow()
|
||||
} else {
|
||||
matches.free.connect(" ").into_cow()
|
||||
};
|
||||
|
||||
exec(string.as_slice());
|
||||
exec(&string[]);
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
pub fn exec(string: &str) {
|
||||
loop {
|
||||
if !pipe_println!("{}", string) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
while pipe_println!("{}", string) { }
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue