| 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 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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; |
| 311 final ArgParser _parser; | 312 final ArgParser _parser; |
| 312 | 313 |
| 313 /** Creates a new command line parser */ | 314 /** Creates a new command line parser */ |
| 314 _CommandLineParser() | 315 CommandLineParser() |
| 315 : _knownFlags = <String>[], | 316 : _knownFlags = <String>[], |
| 316 _parser = new ArgParser(allowTrailingOptions: true); | 317 _parser = new ArgParser(allowTrailingOptions: true); |
| 317 | 318 |
| 318 | 319 |
| 320 ArgParser get parser => _parser; |
| 321 |
| 319 /** | 322 /** |
| 320 * Defines a flag. | 323 * Defines a flag. |
| 321 * | 324 * |
| 322 * See [ArgParser.addFlag()]. | 325 * See [ArgParser.addFlag()]. |
| 323 */ | 326 */ |
| 324 void addFlag(String name, {String abbr, String help, bool defaultsTo: false, | 327 void addFlag(String name, {String abbr, String help, bool defaultsTo: false, |
| 325 bool negatable: true, void callback(bool value), bool hide: false}) { | 328 bool negatable: true, void callback(bool value), bool hide: false}) { |
| 326 _knownFlags.add(name); | 329 _knownFlags.add(name); |
| 327 _parser.addFlag( | 330 _parser.addFlag( |
| 328 name, | 331 name, |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 | 427 |
| 425 _getNextFlagIndex(args, i) { | 428 _getNextFlagIndex(args, i) { |
| 426 for ( ; i < args.length; ++i) { | 429 for ( ; i < args.length; ++i) { |
| 427 if (args[i].startsWith('--')) { | 430 if (args[i].startsWith('--')) { |
| 428 return i; | 431 return i; |
| 429 } | 432 } |
| 430 } | 433 } |
| 431 return i; | 434 return i; |
| 432 } | 435 } |
| 433 } | 436 } |
| OLD | NEW |