From 61a232eb0a43c388a356cac1c2fc5d634ebad48d Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 22 Oct 2013 14:22:10 +0200 Subject: [PATCH] Simplify opt checks --- cat/cat.rs | 16 ++++++++-------- printenv/printenv.rs | 6 +++--- whoami/whoami.rs | 4 ++-- yes/yes.rs | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/cat/cat.rs b/cat/cat.rs index 3f3e063de..413a55247 100644 --- a/cat/cat.rs +++ b/cat/cat.rs @@ -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 = ~[~"-"]; diff --git a/printenv/printenv.rs b/printenv/printenv.rs index ca980415c..5be5aadc3 100644 --- a/printenv/printenv.rs +++ b/printenv/printenv.rs @@ -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"; }; diff --git a/whoami/whoami.rs b/whoami/whoami.rs index 089dc8372..8af54c39a 100644 --- a/whoami/whoami.rs +++ b/whoami/whoami.rs @@ -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; } diff --git a/yes/yes.rs b/yes/yes.rs index 49680ff90..cf237ece0 100644 --- a/yes/yes.rs +++ b/yes/yes.rs @@ -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; }