Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(852)

Unified Diff: lib/src/parser.dart

Issue 975463004: Parse comma-separated multiple values. (Closed) Base URL: git@github.com:dart-lang/args@master
Patch Set: Fix allowed. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | test/parse_test.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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}".');
+ }
}
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | test/parse_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698