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

Side by Side Diff: pkg/analyzer/lib/options.dart

Issue 940093003: Add ignore-unrecognized-flags as an option to the command line options of analysis server (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/analysis_server/lib/src/server/driver.dart ('k') | no next file » | 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 library options; 5 library options;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 8
9 import 'package:args/args.dart'; 9 import 'package:args/args.dart';
10 10
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 File versionFile = new File(versionPath); 126 File versionFile = new File(versionPath);
127 return versionFile.readAsStringSync().trim(); 127 return versionFile.readAsStringSync().trim();
128 } catch (_) { 128 } catch (_) {
129 // This happens when the script is not running in the context of an SDK. 129 // This happens when the script is not running in the context of an SDK.
130 return "<unknown>"; 130 return "<unknown>";
131 } 131 }
132 } 132 }
133 133
134 static CommandLineOptions _parse(List<String> args) { 134 static CommandLineOptions _parse(List<String> args) {
135 args = args.expand((String arg) => arg.split('=')).toList(); 135 args = args.expand((String arg) => arg.split('=')).toList();
136 var parser = new _CommandLineParser() 136 var parser = new CommandLineParser()
137 ..addFlag( 137 ..addFlag(
138 'batch', 138 'batch',
139 abbr: 'b', 139 abbr: 'b',
140 help: 'Run in batch mode', 140 help: 'Run in batch mode',
141 defaultsTo: false, 141 defaultsTo: false,
142 negatable: false) 142 negatable: false)
143 ..addOption('dart-sdk', help: 'The path to the Dart SDK') 143 ..addOption('dart-sdk', help: 'The path to the Dart SDK')
144 ..addOption( 144 ..addOption(
145 'package-root', 145 'package-root',
146 abbr: 'p', 146 abbr: 'p',
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 negatable: false) 201 negatable: false)
202 ..addFlag( 202 ..addFlag(
203 'help', 203 'help',
204 abbr: 'h', 204 abbr: 'h',
205 help: 'Display this help message', 205 help: 'Display this help message',
206 defaultsTo: false, 206 defaultsTo: false,
207 negatable: false) 207 negatable: false)
208 ..addOption( 208 ..addOption(
209 'url-mapping', 209 'url-mapping',
210 help: '--url-mapping=libraryUri,/path/to/library.dart directs the ' 210 help: '--url-mapping=libraryUri,/path/to/library.dart directs the '
211 'analyzer to use "library.dart" as the source for an import ' 211 'analyzer to use "library.dart" as the source for an import ' 'o f "libraryUri"',
212 'of "libraryUri"',
213 allowMultiple: true) 212 allowMultiple: true)
214 // 213 //
215 // Hidden flags. 214 // Hidden flags.
216 // 215 //
217 ..addFlag( 216 ..addFlag(
218 'enable-async', 217 'enable-async',
219 help: 'Enable support for the proposed async feature', 218 help: 'Enable support for the proposed async feature',
220 defaultsTo: false, 219 defaultsTo: false,
221 negatable: false, 220 negatable: false,
222 hide: true) 221 hide: true)
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 Map<String, String> customUrlMappings = <String, String>{}; 274 Map<String, String> customUrlMappings = <String, String>{};
276 for (String mapping in results['url-mapping']) { 275 for (String mapping in results['url-mapping']) {
277 List<String> splitMapping = mapping.split(','); 276 List<String> splitMapping = mapping.split(',');
278 if (splitMapping.length != 2) { 277 if (splitMapping.length != 2) {
279 _showUsage(parser); 278 _showUsage(parser);
280 exit(15); 279 exit(15);
281 } 280 }
282 customUrlMappings[splitMapping[0]] = splitMapping[1]; 281 customUrlMappings[splitMapping[0]] = splitMapping[1];
283 } 282 }
284 return new CommandLineOptions._fromArgs( 283 return new CommandLineOptions._fromArgs(
285 results, definedVariables, customUrlMappings); 284 results,
285 definedVariables,
286 customUrlMappings);
286 } on FormatException catch (e) { 287 } on FormatException catch (e) {
287 print(e.message); 288 print(e.message);
288 _showUsage(parser); 289 _showUsage(parser);
289 exit(15); 290 exit(15);
290 } 291 }
291 292
292 } 293 }
293 294
294 static _showUsage(parser) { 295 static _showUsage(parser) {
295 print('Usage: $_BINARY_NAME [options...] <libraries to analyze...>'); 296 print('Usage: $_BINARY_NAME [options...] <libraries to analyze...>');
296 print(parser.getUsage()); 297 print(parser.getUsage());
297 print(''); 298 print('');
298 print('For more information, see http://www.dartlang.org/tools/analyzer.'); 299 print('For more information, see http://www.dartlang.org/tools/analyzer.');
299 } 300 }
300 } 301 }
301 302
302 /** 303 /**
303 * Commandline argument parser. 304 * Commandline argument parser.
304 * 305 *
305 * TODO(pquitslund): when the args package supports ignoring unrecognized 306 * TODO(pquitslund): when the args package supports ignoring unrecognized
306 * options/flags, this class can be replaced with a simple [ArgParser] instance. 307 * options/flags, this class can be replaced with a simple [ArgParser] instance.
307 */ 308 */
308 class _CommandLineParser { 309 class CommandLineParser {
309 310
310 final List<String> _knownFlags; 311 final List<String> _knownFlags;
312 final bool _alwaysIgnoreUnrecognized;
311 final ArgParser _parser; 313 final ArgParser _parser;
312 314
313 /** Creates a new command line parser */ 315 /** Creates a new command line parser */
314 _CommandLineParser() 316 CommandLineParser({bool alwaysIgnoreUnrecognized: false})
315 : _knownFlags = <String>[], 317 : _knownFlags = <String>[],
318 _alwaysIgnoreUnrecognized = alwaysIgnoreUnrecognized,
316 _parser = new ArgParser(allowTrailingOptions: true); 319 _parser = new ArgParser(allowTrailingOptions: true);
317 320
318 321
322 ArgParser get parser => _parser;
323
319 /** 324 /**
320 * Defines a flag. 325 * Defines a flag.
321 * 326 *
322 * See [ArgParser.addFlag()]. 327 * See [ArgParser.addFlag()].
323 */ 328 */
324 void addFlag(String name, {String abbr, String help, bool defaultsTo: false, 329 void addFlag(String name, {String abbr, String help, bool defaultsTo: false,
325 bool negatable: true, void callback(bool value), bool hide: false}) { 330 bool negatable: true, void callback(bool value), bool hide: false}) {
326 _knownFlags.add(name); 331 _knownFlags.add(name);
327 _parser.addFlag( 332 _parser.addFlag(
328 name, 333 name,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 definedVariables[arg.substring(2)] = args[++i]; 391 definedVariables[arg.substring(2)] = args[++i];
387 } else { 392 } else {
388 remainingArgs.add(arg); 393 remainingArgs.add(arg);
389 } 394 }
390 } 395 }
391 return remainingArgs; 396 return remainingArgs;
392 } 397 }
393 398
394 List<String> _filterUnknowns(args) { 399 List<String> _filterUnknowns(args) {
395 400
396 // Only filter args if the ignore flag is specified. 401 // Only filter args if the ignore flag is specified, or if
397 if (!args.contains('--ignore-unrecognized-flags')) { 402 // _alwaysIgnoreUnrecognized was set to true
403 if (_alwaysIgnoreUnrecognized ||
404 !args.contains('--ignore-unrecognized-flags')) {
Brian Wilkerson 2015/02/19 21:58:21 This looks wrong. Previously, we would return imme
398 return args; 405 return args;
399 } 406 }
400 //TODO(pquitslund): replace w/ the following once library skew issues are 407 //TODO(pquitslund): replace w/ the following once library skew issues are
401 // sorted out 408 // sorted out
402 //return args.where((arg) => !arg.startsWith('--') || 409 //return args.where((arg) => !arg.startsWith('--') ||
403 // _knownFlags.contains(arg.substring(2))); 410 // _knownFlags.contains(arg.substring(2)));
404 411
405 // Filter all unrecognized flags and options. 412 // Filter all unrecognized flags and options.
406 var filtered = <String>[]; 413 var filtered = <String>[];
407 for (var i = 0; i < args.length; ++i) { 414 for (var i = 0; i < args.length; ++i) {
(...skipping 16 matching lines...) Expand all
424 431
425 _getNextFlagIndex(args, i) { 432 _getNextFlagIndex(args, i) {
426 for ( ; i < args.length; ++i) { 433 for ( ; i < args.length; ++i) {
427 if (args[i].startsWith('--')) { 434 if (args[i].startsWith('--')) {
428 return i; 435 return i;
429 } 436 }
430 } 437 }
431 return i; 438 return i;
432 } 439 }
433 } 440 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/server/driver.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698