diff --git a/src/libstd/getopts.rs b/src/libstd/getopts.rs index 2090a3728db52..95883e62e0b7e 100644 --- a/src/libstd/getopts.rs +++ b/src/libstd/getopts.rs @@ -369,9 +369,9 @@ pub fn opt_count(mm: &Matches, nm: &str) -> uint { pub fn opts_present(mm: &Matches, names: &[~str]) -> bool { for vec::each(names) |nm| { match find_opt(mm.opts, mkname(*nm)) { - Some(_) => return true, - None => () - } + Some(id) if !mm.vals[id].is_empty() => return true, + _ => (), + }; } false } @@ -1174,7 +1174,7 @@ mod tests { #[test] pub fn test_multi() { let args = ~[~"-e", ~"foo", ~"--encrypt", ~"foo"]; - let opts = ~[optopt(~"e"), optopt(~"encrypt")]; + let opts = ~[optopt(~"e"), optopt(~"encrypt"), optopt(~"f")]; let matches = &match getopts(args, opts) { result::Ok(m) => m, result::Err(_) => fail!() @@ -1183,6 +1183,7 @@ mod tests { fail_unless!(opts_present(matches, ~[~"encrypt"])); fail_unless!(opts_present(matches, ~[~"encrypt", ~"e"])); fail_unless!(opts_present(matches, ~[~"e", ~"encrypt"])); + fail_unless!(!opts_present(matches, ~[~"f"])); fail_unless!(!opts_present(matches, ~[~"thing"])); fail_unless!(!opts_present(matches, ~[]));