Chromium Code Reviews| Index: lib/src/parser.dart |
| diff --git a/lib/src/parser.dart b/lib/src/parser.dart |
| index 1e297b0e68b35069f57527e85ac3f6d8a63e781f..37c9652095cc442e4ca197f6fcc8a362a73d8d2c 100644 |
| --- a/lib/src/parser.dart |
| +++ b/lib/src/parser.dart |
| @@ -254,17 +254,25 @@ class Parser { |
| /// Validates and stores [value] as the value for [option]. |
| void setOption(Map results, Option option, value) { |
| - // See if it's one of the allowed values. |
| - if (option.allowed != null) { |
| - validate(option.allowed.any((allow) => allow == value), |
| - '"$value" is not an allowed value for option "${option.name}".'); |
| + if (!option.isMultiple) { |
| + _validateAllowed(option, value); |
| + results[option.name] = value; |
| + return; |
| } |
| - if (option.isMultiple) { |
| - var list = results.putIfAbsent(option.name, () => []); |
| - list.add(value); |
| - } else { |
| - results[option.name] = value; |
| + var list = results.putIfAbsent(option.name, () => []); |
| + assert(value is String); |
|
Bob Nystrom
2015/03/03 17:36:26
Value can only be a string or bool, right? And fla
Sean Eagan
2015/03/03 20:21:23
They don't? I know some people like to use `-vvv`
nweiz
2015/03/03 20:22:18
Done.
|
| + for (var subValue in value.split(",")) { |
|
Bob Nystrom
2015/03/03 17:36:26
"subValue" -> "subvalue". Or maybe just "element"?
nweiz
2015/03/03 20:22:18
Done.
|
| + _validateAllowed(option, subValue); |
| + list.add(subValue); |
| } |
| } |
| + |
| + /// Validates that [value] is allowed as a value of [option]. |
| + void _validateAllowed(Option option, value) { |
|
Bob Nystrom
2015/03/03 17:36:26
Annotate value as String.
nweiz
2015/03/03 20:22:18
Done.
|
| + if (option.allowed == null) return; |
| + |
| + validate(option.allowed.any((allow) => allow == value), |
|
Bob Nystrom
2015/03/03 17:36:26
.contains(value)
?
nweiz
2015/03/03 20:22:18
Done.
|
| + '"$value" is not an allowed value for option "${option.name}".'); |
| + } |
| } |