From a0f855e48812d8ce5c0c2d4e7496aa0e4643bdb3 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sat, 21 May 2011 21:48:43 -0400 Subject: stdlib: Report an error when getopts is given an argument to a flag option --- src/lib/getopts.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/lib') diff --git a/src/lib/getopts.rs b/src/lib/getopts.rs index 7318f273d0f..52723575460 100644 --- a/src/lib/getopts.rs +++ b/src/lib/getopts.rs @@ -98,6 +98,7 @@ tag fail_ { unrecognized_option(str); option_missing(str); option_duplicated(str); + unexpected_argument(str); } fn fail_str(fail_ f) -> str { @@ -114,6 +115,9 @@ fn fail_str(fail_ f) -> str { case (option_duplicated(?nm)) { ret "option '" + nm + "' given more than once."; } + case (unexpected_argument(?nm)) { + ret "Option " + nm + " does not take an argument."; + } } } @@ -173,6 +177,9 @@ fn getopts(vec[str] args, vec[opt] opts) -> result { } alt (opts.(optid).hasarg) { case (no) { + if (!option::is_none[str](i_arg)) { + ret failure(unexpected_argument(name_str(nm))); + } vec::push[optval](vals.(optid), given); } case (maybe) { -- cgit 1.4.1-3-g733a5