1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-30 04:27:45 +00:00

Merge pull request #506 from Stebalien/yes-cleanup

Cleanup `yes`
This commit is contained in:
Alex Lyon 2015-01-24 20:25:04 -08:00
commit 70c6fb0887

View file

@ -16,6 +16,7 @@ extern crate getopts;
extern crate libc; extern crate libc;
use std::io::print; use std::io::print;
use std::borrow::IntoCow;
#[path = "../common/util.rs"] #[path = "../common/util.rs"]
#[macro_use] #[macro_use]
@ -24,7 +25,7 @@ mod util;
static NAME: &'static str = "yes"; static NAME: &'static str = "yes";
pub fn uumain(args: Vec<String>) -> isize { pub fn uumain(args: Vec<String>) -> isize {
let program = args[0].clone(); let program = &args[0];
let opts = [ let opts = [
getopts::optflag("h", "help", "display this help and exit"), getopts::optflag("h", "help", "display this help and exit"),
getopts::optflag("V", "version", "output version information 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!("Usage:");
println!(" {0} [STRING]... [OPTION]...", program); println!(" {0} [STRING]... [OPTION]...", program);
println!(""); 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; return 0;
} }
if matches.opt_present("version") { if matches.opt_present("version") {
println!("yes 1.0.0"); println!("yes 1.0.0");
return 0; return 0;
} }
let mut string = "y".to_string(); let string = if matches.free.is_empty() {
if !matches.free.is_empty() { "y".into_cow()
string = matches.free.connect(" "); } else {
} matches.free.connect(" ").into_cow()
};
exec(string.as_slice()); exec(&string[]);
0 0
} }
pub fn exec(string: &str) { pub fn exec(string: &str) {
loop { while pipe_println!("{}", string) { }
if !pipe_println!("{}", string) {
break;
}
}
} }