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

View file

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

View file

@ -50,7 +50,7 @@ fn main() {
Ok(m) => m,
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("");
println("Usage:");
@ -59,7 +59,7 @@ fn main() {
print(groups::usage("print effective userid", opts));
return;
}
if matches.opt_present("V") || matches.opt_present("version") {
if matches.opt_present("version") {
println("whoami 1.0.0");
return;
}

View file

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