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 library analyzer.src.command_line.arguments; | 5 library analyzer.src.command_line.arguments; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'package:analyzer/file_system/file_system.dart'; | 9 import 'package:analyzer/file_system/file_system.dart'; |
10 import 'package:analyzer/src/context/builder.dart'; | 10 import 'package:analyzer/src/context/builder.dart'; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 negatable: false, | 158 negatable: false, |
159 hide: true); | 159 hide: true); |
160 // parser.addFlag('enable_type_checks', | 160 // parser.addFlag('enable_type_checks', |
161 // help: 'Check types in constant evaluation.', | 161 // help: 'Check types in constant evaluation.', |
162 // defaultsTo: false, | 162 // defaultsTo: false, |
163 // negatable: false, | 163 // negatable: false, |
164 // hide: true); | 164 // hide: true); |
165 } | 165 } |
166 | 166 |
167 /** | 167 /** |
168 * Find arguments of the form -Dkey=value | |
169 * or argument pairs of the form -Dkey value | |
170 * and place those key/value pairs into [definedVariables]. | |
171 * Return a list of arguments with the key/value arguments removed. | |
172 */ | |
173 List<String> extractDefinedVariables( | |
Brian Wilkerson
2016/12/14 17:47:35
This is already being done as part of createContex
danrubel
2016/12/14 18:06:56
That makes sense as a long term goal, but I'd like
| |
174 List<String> args, Map<String, String> definedVariables) { | |
175 int count = args.length; | |
176 List<String> remainingArgs = <String>[]; | |
177 for (int i = 0; i < count; i++) { | |
178 String arg = args[i]; | |
179 if (arg == '--') { | |
180 while (i < count) { | |
181 remainingArgs.add(args[i++]); | |
182 } | |
183 } else if (arg.startsWith("-D")) { | |
184 if (i + 1 < count) { | |
185 definedVariables[arg.substring(2)] = args[++i]; | |
186 } else { | |
187 remainingArgs.add(arg); | |
188 } | |
189 } else { | |
190 remainingArgs.add(arg); | |
191 } | |
192 } | |
193 return remainingArgs; | |
194 } | |
195 | |
196 /** | |
168 * Return a list of command-line arguments containing all of the given [args] | 197 * Return a list of command-line arguments containing all of the given [args] |
169 * that are defined by the given [parser]. An argument is considered to be | 198 * that are defined by the given [parser]. An argument is considered to be |
170 * defined by the parser if | 199 * defined by the parser if |
171 * - it starts with '--' and the rest of the argument (minus any value | 200 * - it starts with '--' and the rest of the argument (minus any value |
172 * introduced by '=') is the name of a known option, | 201 * introduced by '=') is the name of a known option, |
173 * - it starts with '-' and the rest of the argument (minus any value | 202 * - it starts with '-' and the rest of the argument (minus any value |
174 * introduced by '=') is the name of a known abbreviation, or | 203 * introduced by '=') is the name of a known abbreviation, or |
175 * - it starts with something other than '--' or '-'. | 204 * - it starts with something other than '--' or '-'. |
176 * | 205 * |
177 * This function allows command-line tools to implement the | 206 * This function allows command-line tools to implement the |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 .replaceAll('\r\n', '\n') | 276 .replaceAll('\r\n', '\n') |
248 .replaceAll('\r', '\n') | 277 .replaceAll('\r', '\n') |
249 .split('\n') | 278 .split('\n') |
250 .where((String line) => line.isNotEmpty)); | 279 .where((String line) => line.isNotEmpty)); |
251 } on FileSystemException catch (e) { | 280 } on FileSystemException catch (e) { |
252 throw new Exception('Failed to read file specified by $lastArg : $e'); | 281 throw new Exception('Failed to read file specified by $lastArg : $e'); |
253 } | 282 } |
254 } | 283 } |
255 return args; | 284 return args; |
256 } | 285 } |
OLD | NEW |