OLD | NEW |
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 library args.src.parser; | 5 library args.src.parser; |
6 | 6 |
7 import '../args.dart'; | 7 import '../args.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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 grammar.options.forEach((name, option) { | 88 grammar.options.forEach((name, option) { |
89 if (option.allowMultiple && | 89 if (option.allowMultiple && |
90 results[name].length == 0 && | 90 results[name].length == 0 && |
91 option.defaultValue != null) { | 91 option.defaultValue != null) { |
92 results[name].add(option.defaultValue); | 92 results[name].add(option.defaultValue); |
93 } | 93 } |
94 if (option.callback != null) option.callback(results[name]); | 94 if (option.callback != null) option.callback(results[name]); |
95 }); | 95 }); |
96 | 96 |
97 // Add in the leftover arguments we didn't parse to the innermost command. | 97 // Add in the leftover arguments we didn't parse to the innermost command. |
98 var rest = args.toList(growable: true); | 98 var rest = args.toList(); |
99 args.clear(); | 99 args.clear(); |
100 return new ArgResults(results, commandName, commandResults, rest); | 100 return new ArgResults(results, commandName, commandResults, rest); |
101 } | 101 } |
102 | 102 |
103 /** | 103 /** |
104 * Pulls the value for [option] from the second argument in [args]. Validates | 104 * Pulls the value for [option] from the second argument in [args]. Validates |
105 * that there is a valid value there. | 105 * that there is a valid value there. |
106 */ | 106 */ |
107 void readNextArgAsValue(Option option) { | 107 void readNextArgAsValue(Option option) { |
108 // Take the option argument from the next command line arg. | 108 // Take the option argument from the next command line arg. |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 '"$value" is not an allowed value for option "${option.name}".'); | 272 '"$value" is not an allowed value for option "${option.name}".'); |
273 } | 273 } |
274 | 274 |
275 if (option.allowMultiple) { | 275 if (option.allowMultiple) { |
276 results[option.name].add(value); | 276 results[option.name].add(value); |
277 } else { | 277 } else { |
278 results[option.name] = value; | 278 results[option.name] = value; |
279 } | 279 } |
280 } | 280 } |
281 } | 281 } |
OLD | NEW |