diff options
| author | Brian Anderson <andersrb@gmail.com> | 2011-05-21 21:48:43 -0400 |
|---|---|---|
| committer | Brian Anderson <andersrb@gmail.com> | 2011-05-22 02:10:09 -0400 |
| commit | a0f855e48812d8ce5c0c2d4e7496aa0e4643bdb3 (patch) | |
| tree | 59ce568617c1367e49db134b4c8df79008af535a /src/lib | |
| parent | 079711d5f62bc440a83066fda87069b611a8e878 (diff) | |
| download | rust-a0f855e48812d8ce5c0c2d4e7496aa0e4643bdb3.tar.gz rust-a0f855e48812d8ce5c0c2d4e7496aa0e4643bdb3.zip | |
stdlib: Report an error when getopts is given an argument to a flag option
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/getopts.rs | 7 |
1 files changed, 7 insertions, 0 deletions
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) { |
