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

Side by Side Diff: lib/src/parser.dart

Issue 1954923002: Ensure that lists are reified. (Closed) Base URL: git@github.com:dart-lang/args@master
Patch Set: Created 4 years, 7 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 unified diff | Download patch
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'arg_parser.dart'; 5 import 'arg_parser.dart';
6 import 'arg_results.dart'; 6 import 'arg_results.dart';
7 import 'option.dart'; 7 import 'option.dart';
8 8
9 final _SOLO_OPT = new RegExp(r'^-([a-zA-Z0-9])$'); 9 final _SOLO_OPT = new RegExp(r'^-([a-zA-Z0-9])$');
10 final _ABBR_OPT = new RegExp(r'^-([a-zA-Z0-9]+)(.*)$'); 10 final _ABBR_OPT = new RegExp(r'^-([a-zA-Z0-9]+)(.*)$');
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 /// a flag. 251 /// a flag.
252 void setOption(Map results, Option option, String value) { 252 void setOption(Map results, Option option, String value) {
253 assert(!option.isFlag); 253 assert(!option.isFlag);
254 254
255 if (!option.isMultiple) { 255 if (!option.isMultiple) {
256 _validateAllowed(option, value); 256 _validateAllowed(option, value);
257 results[option.name] = value; 257 results[option.name] = value;
258 return; 258 return;
259 } 259 }
260 260
261 var list = results.putIfAbsent(option.name, () => []); 261 var list = results.putIfAbsent(option.name, () => <String>[]);
262 262
263 if (option.splitCommas) { 263 if (option.splitCommas) {
264 for (var element in value.split(",")) { 264 for (var element in value.split(",")) {
265 _validateAllowed(option, element); 265 _validateAllowed(option, element);
266 list.add(element); 266 list.add(element);
267 } 267 }
268 } else { 268 } else {
269 _validateAllowed(option, value); 269 _validateAllowed(option, value);
270 list.add(value); 270 list.add(value);
271 } 271 }
272 } 272 }
273 273
274 /// Validates and stores [value] as the value for [option], which must be a 274 /// Validates and stores [value] as the value for [option], which must be a
275 /// flag. 275 /// flag.
276 void setFlag(Map results, Option option, bool value) { 276 void setFlag(Map results, Option option, bool value) {
277 assert(option.isFlag); 277 assert(option.isFlag);
278 results[option.name] = value; 278 results[option.name] = value;
279 } 279 }
280 280
281 /// Validates that [value] is allowed as a value of [option]. 281 /// Validates that [value] is allowed as a value of [option].
282 void _validateAllowed(Option option, String value) { 282 void _validateAllowed(Option option, String value) {
283 if (option.allowed == null) return; 283 if (option.allowed == null) return;
284 284
285 validate(option.allowed.contains(value), 285 validate(option.allowed.contains(value),
286 '"$value" is not an allowed value for option "${option.name}".'); 286 '"$value" is not an allowed value for option "${option.name}".');
287 } 287 }
288 } 288 }
OLDNEW
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698