1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Simplify opt checks

This commit is contained in:
Jordi Boggiano 2013-10-22 14:22:10 +02:00
parent a4899a1b31
commit 61a232eb0a
4 changed files with 15 additions and 15 deletions

View file

@ -42,7 +42,7 @@ fn main() {
return return
} }
}; };
if matches.opts_present([~"h", ~"help"]) { if matches.opt_present("help") {
println("cat 1.0.0"); println("cat 1.0.0");
println(""); println("");
println("Usage:"); println("Usage:");
@ -53,22 +53,22 @@ fn main() {
println("With no FILE, or when FILE is -, read standard input."); println("With no FILE, or when FILE is -, read standard input.");
return; return;
} }
if matches.opts_present([~"V", ~"version"]) { if matches.opt_present("version") {
println("cat 1.0.0"); println("cat 1.0.0");
return; return;
} }
let mut number_mode = NumberNone; let mut number_mode = NumberNone;
if matches.opts_present([~"n", ~"number"]) { if matches.opt_present("number") {
number_mode = NumberAll; number_mode = NumberAll;
} }
if matches.opts_present([~"b", ~"number-nonblank"]) { if matches.opt_present("number-nonblank") {
number_mode = NumberNonEmpty; number_mode = NumberNonEmpty;
} }
let show_nonprint = matches.opts_present([~"v", ~"show-nonprinting", ~"A", ~"show-all", ~"t", ~"e"]); let show_nonprint = matches.opts_present([~"show-nonprinting", ~"show-all", ~"t", ~"e"]);
let show_ends = matches.opts_present([~"E", ~"show-ends", ~"A", ~"show-all", ~"e"]); let show_ends = matches.opts_present([~"show-ends", ~"show-all", ~"e"]);
let show_tabs = matches.opts_present([~"T", ~"show-tabs", ~"A", ~"show-all", ~"t"]); let show_tabs = matches.opts_present([~"show-tabs", ~"show-all", ~"t"]);
let squeeze_blank = matches.opts_present([~"s", ~"squeeze-blank"]); let squeeze_blank = matches.opt_present("squeeze-blank");
let mut files = matches.free; let mut files = matches.free;
if files.is_empty() { if files.is_empty() {
files = ~[~"-"]; files = ~[~"-"];

View file

@ -34,7 +34,7 @@ fn main() {
return return
} }
}; };
if matches.opts_present([~"h", ~"help"]) { if matches.opt_present("help") {
println("printenv 1.0.0"); println("printenv 1.0.0");
println(""); println("");
println("Usage:"); println("Usage:");
@ -43,12 +43,12 @@ fn main() {
print(groups::usage("Prints the given environment VARIABLE(s), otherwise prints them all.", opts)); print(groups::usage("Prints the given environment VARIABLE(s), otherwise prints them all.", opts));
return; return;
} }
if matches.opts_present([~"V", ~"version"]) { if matches.opt_present("version") {
println("printenv 1.0.0"); println("printenv 1.0.0");
return; return;
} }
let mut separator = "\n"; let mut separator = "\n";
if matches.opts_present([~"0", ~"null"]) { if matches.opt_present("null") {
separator = "\x00"; separator = "\x00";
}; };

View file

@ -50,7 +50,7 @@ fn main() {
Ok(m) => m, Ok(m) => m,
Err(f) => fail2!(f.to_err_msg()), Err(f) => fail2!(f.to_err_msg()),
}; };
if matches.opt_present("h") || matches.opt_present("help") { if matches.opt_present("help") {
println("whoami 1.0.0"); println("whoami 1.0.0");
println(""); println("");
println("Usage:"); println("Usage:");
@ -59,7 +59,7 @@ fn main() {
print(groups::usage("print effective userid", opts)); print(groups::usage("print effective userid", opts));
return; return;
} }
if matches.opt_present("V") || matches.opt_present("version") { if matches.opt_present("version") {
println("whoami 1.0.0"); println("whoami 1.0.0");
return; return;
} }

View file

@ -33,7 +33,7 @@ fn main() {
return return
} }
}; };
if matches.opts_present([~"h", ~"help"]) { if matches.opt_present("help") {
println("yes 1.0.0"); println("yes 1.0.0");
println(""); println("");
println("Usage:"); println("Usage:");
@ -42,7 +42,7 @@ fn main() {
print(groups::usage("Repeatedly output a line with all specified STRING(s), or 'y'.", opts)); print(groups::usage("Repeatedly output a line with all specified STRING(s), or 'y'.", opts));
return; return;
} }
if matches.opts_present([~"V", ~"version"]) { if matches.opt_present("version") {
println("yes 1.0.0"); println("yes 1.0.0");
return; return;
} }