OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 'dart:io'; | 5 import 'dart:io'; |
6 | 6 |
7 import 'package:args/args.dart'; | 7 import 'package:args/args.dart'; |
8 import 'package:boolean_selector/boolean_selector.dart'; | 8 import 'package:boolean_selector/boolean_selector.dart'; |
9 | 9 |
10 import '../../backend/test_platform.dart'; | 10 import '../../backend/test_platform.dart'; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 /// | 124 /// |
125 /// This is used to provide access to the arg results across helper methods. | 125 /// This is used to provide access to the arg results across helper methods. |
126 class _Parser { | 126 class _Parser { |
127 /// The parsed options. | 127 /// The parsed options. |
128 final ArgResults _options; | 128 final ArgResults _options; |
129 | 129 |
130 _Parser(List<String> args) : _options = _parser.parse(args); | 130 _Parser(List<String> args) : _options = _parser.parse(args); |
131 | 131 |
132 /// Returns the parsed configuration. | 132 /// Returns the parsed configuration. |
133 Configuration parse() { | 133 Configuration parse() { |
134 var patterns = _options['name'] | 134 var patterns = (_options['name'] as List<String>) |
135 .map((value) => _wrapFormatException('name', () => new RegExp(value))) | 135 .map/*<Pattern>*/( |
| 136 (value) => _wrapFormatException('name', () => new RegExp(value))) |
136 .toList() | 137 .toList() |
137 ..addAll(_options['plain-name']); | 138 ..addAll(_options['plain-name'] as List<String>); |
138 | 139 |
139 var includeTagSet = new Set.from(_options['tags'] ?? []) | 140 var includeTagSet = new Set.from(_options['tags'] ?? []) |
140 ..addAll(_options['tag'] ?? []); | 141 ..addAll(_options['tag'] ?? []); |
141 | 142 |
142 var includeTags = includeTagSet.fold(BooleanSelector.all, (selector, tag) { | 143 var includeTags = includeTagSet.fold(BooleanSelector.all, (selector, tag) { |
143 var tagSelector = new BooleanSelector.parse(tag); | 144 var tagSelector = new BooleanSelector.parse(tag); |
144 return selector.intersection(tagSelector); | 145 return selector.intersection(tagSelector); |
145 }); | 146 }); |
146 | 147 |
147 var excludeTagSet = new Set.from(_options['exclude-tags'] ?? []) | 148 var excludeTagSet = new Set.from(_options['exclude-tags'] ?? []) |
(...skipping 26 matching lines...) Expand all Loading... |
174 pauseAfterLoad: _ifParsed('pause-after-load'), | 175 pauseAfterLoad: _ifParsed('pause-after-load'), |
175 color: _ifParsed('color'), | 176 color: _ifParsed('color'), |
176 packageRoot: _ifParsed('package-root'), | 177 packageRoot: _ifParsed('package-root'), |
177 reporter: _ifParsed('reporter'), | 178 reporter: _ifParsed('reporter'), |
178 pubServePort: _parseOption('pub-serve', int.parse), | 179 pubServePort: _parseOption('pub-serve', int.parse), |
179 concurrency: _parseOption('concurrency', int.parse), | 180 concurrency: _parseOption('concurrency', int.parse), |
180 shardIndex: shardIndex, | 181 shardIndex: shardIndex, |
181 totalShards: totalShards, | 182 totalShards: totalShards, |
182 timeout: _parseOption('timeout', (value) => new Timeout.parse(value)), | 183 timeout: _parseOption('timeout', (value) => new Timeout.parse(value)), |
183 patterns: patterns, | 184 patterns: patterns, |
184 platforms: _ifParsed('platform')?.map(TestPlatform.find), | 185 platforms: (_ifParsed('platform') as List<String>) |
185 chosenPresets: _ifParsed('preset'), | 186 ?.map(TestPlatform.find), |
| 187 chosenPresets: _ifParsed('preset') as List<String>, |
186 paths: _options.rest.isEmpty ? null : _options.rest, | 188 paths: _options.rest.isEmpty ? null : _options.rest, |
187 includeTags: includeTags, | 189 includeTags: includeTags, |
188 excludeTags: excludeTags); | 190 excludeTags: excludeTags); |
189 } | 191 } |
190 | 192 |
191 /// Returns the parsed option for [name], or `null` if none was parsed. | 193 /// Returns the parsed option for [name], or `null` if none was parsed. |
192 /// | 194 /// |
193 /// If the user hasn't explicitly chosen a value, we want to pass null values | 195 /// If the user hasn't explicitly chosen a value, we want to pass null values |
194 /// to [new Configuration] so that it considers those fields unset when | 196 /// to [new Configuration] so that it considers those fields unset when |
195 /// merging with configuration from the config file. | 197 /// merging with configuration from the config file. |
196 _ifParsed(String name) => _options.wasParsed(name) ? _options[name] : null; | 198 _ifParsed(String name) => _options.wasParsed(name) ? _options[name] : null; |
197 | 199 |
198 /// Runs [parse] on the value of the option [name], and wraps any | 200 /// Runs [parse] on the value of the option [name], and wraps any |
199 /// [FormatException] it throws with additional information. | 201 /// [FormatException] it throws with additional information. |
200 _parseOption(String name, parse(value)) { | 202 /*=T*/ _parseOption/*<T>*/(String name, /*=T*/ parse(String value)) { |
201 if (!_options.wasParsed(name)) return null; | 203 if (!_options.wasParsed(name)) return null; |
202 | 204 |
203 var value = _options[name]; | 205 var value = _options[name]; |
204 if (value == null) return null; | 206 if (value == null) return null; |
205 | 207 |
206 return _wrapFormatException(name, () => parse(value)); | 208 return _wrapFormatException(name, () => parse(value as String)); |
207 } | 209 } |
208 | 210 |
209 /// Runs [parse], and wraps any [FormatException] it throws with additional | 211 /// Runs [parse], and wraps any [FormatException] it throws with additional |
210 /// information. | 212 /// information. |
211 _wrapFormatException(String name, parse()) { | 213 /*=T*/ _wrapFormatException/*<T>*/(String name, /*=T*/ parse()) { |
212 try { | 214 try { |
213 return parse(); | 215 return parse(); |
214 } on FormatException catch (error) { | 216 } on FormatException catch (error) { |
215 throw new FormatException('Couldn\'t parse --$name "${_options[name]}": ' | 217 throw new FormatException('Couldn\'t parse --$name "${_options[name]}": ' |
216 '${error.message}'); | 218 '${error.message}'); |
217 } | 219 } |
218 } | 220 } |
219 } | 221 } |
OLD | NEW |