| 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 |
| 11 const _BINARY_NAME = 'dartanalyzer'; | 11 const _BINARY_NAME = 'dartanalyzer'; |
| 12 | 12 |
| 13 /** | 13 /** |
| 14 * Analyzer commandline configuration options. | 14 * Analyzer commandline configuration options. |
| 15 */ | 15 */ |
| 16 class CommandLineOptions { | 16 class CommandLineOptions { |
| 17 | 17 /** The path to the dart SDK */ |
| 18 /** Batch mode (for unit testing) */ | 18 final String dartSdkPath; |
| 19 final bool shouldBatch; | |
| 20 | |
| 21 /** Whether to use machine format for error display */ | |
| 22 final bool machineFormat; | |
| 23 | |
| 24 /** Whether to display version information */ | |
| 25 final bool displayVersion; | |
| 26 | 19 |
| 27 /** A table mapping the names of defined variables to their values. */ | 20 /** A table mapping the names of defined variables to their values. */ |
| 28 final Map<String, String> definedVariables; | 21 final Map<String, String> definedVariables; |
| 29 | 22 |
| 30 /** Whether to report hints */ | 23 /** Whether to report hints */ |
| 31 final bool disableHints; | 24 final bool disableHints; |
| 32 | 25 |
| 26 /** Whether to display version information */ |
| 27 final bool displayVersion; |
| 28 |
| 29 /** Whether to enable support for the proposed async feature. */ |
| 30 final bool enableAsync; |
| 31 |
| 32 /** Whether to enable support for the proposed enum feature. */ |
| 33 final bool enableEnum; |
| 34 |
| 33 /** Whether to ignore unrecognized flags */ | 35 /** Whether to ignore unrecognized flags */ |
| 34 final bool ignoreUnrecognizedFlags; | 36 final bool ignoreUnrecognizedFlags; |
| 35 | 37 |
| 38 /** Whether to log additional analysis messages and exceptions */ |
| 39 final bool log; |
| 40 |
| 41 /** Whether to use machine format for error display */ |
| 42 final bool machineFormat; |
| 43 |
| 44 /** The path to the package root */ |
| 45 final String packageRootPath; |
| 46 |
| 36 /** Whether to show performance statistics */ | 47 /** Whether to show performance statistics */ |
| 37 final bool perf; | 48 final bool perf; |
| 38 | 49 |
| 50 /** Batch mode (for unit testing) */ |
| 51 final bool shouldBatch; |
| 52 |
| 39 /** Whether to show package: warnings */ | 53 /** Whether to show package: warnings */ |
| 40 final bool showPackageWarnings; | 54 final bool showPackageWarnings; |
| 41 | 55 |
| 42 /** Whether to show SDK warnings */ | 56 /** Whether to show SDK warnings */ |
| 43 final bool showSdkWarnings; | 57 final bool showSdkWarnings; |
| 44 | 58 |
| 59 /** The source files to analyze */ |
| 60 final List<String> sourceFiles; |
| 61 |
| 45 /** Whether to show both cold and hot performance statistics */ | 62 /** Whether to show both cold and hot performance statistics */ |
| 46 final bool warmPerf; | 63 final bool warmPerf; |
| 47 | 64 |
| 48 /** Whether to treat warnings as fatal */ | 65 /** Whether to treat warnings as fatal */ |
| 49 final bool warningsAreFatal; | 66 final bool warningsAreFatal; |
| 50 | 67 |
| 51 /** The path to the dart SDK */ | |
| 52 final String dartSdkPath; | |
| 53 | |
| 54 /** The path to the package root */ | |
| 55 final String packageRootPath; | |
| 56 | |
| 57 /** The source files to analyze */ | |
| 58 final List<String> sourceFiles; | |
| 59 | |
| 60 /** Whether to log additional analysis messages and exceptions */ | |
| 61 final bool log; | |
| 62 | |
| 63 /** | 68 /** |
| 64 * Initialize options from the given parsed [args]. | 69 * Initialize options from the given parsed [args]. |
| 65 */ | 70 */ |
| 66 CommandLineOptions._fromArgs(ArgResults args, Map<String, String> definedVaria
bles) | 71 CommandLineOptions._fromArgs(ArgResults args, Map<String, String> definedVaria
bles) |
| 67 : shouldBatch = args['batch'], | 72 : dartSdkPath = args['dart-sdk'], |
| 73 this.definedVariables = definedVariables, |
| 74 disableHints = args['no-hints'], |
| 75 displayVersion = args['version'], |
| 76 enableAsync = args['enable-async'], |
| 77 enableEnum = args['enable-enum'], |
| 78 ignoreUnrecognizedFlags = args['ignore-unrecognized-flags'], |
| 79 log = args['log'], |
| 68 machineFormat = args['machine'] || args['format'] == 'machine', | 80 machineFormat = args['machine'] || args['format'] == 'machine', |
| 69 displayVersion = args['version'], | 81 packageRootPath = args['package-root'], |
| 70 disableHints = args['no-hints'], | |
| 71 ignoreUnrecognizedFlags = args['ignore-unrecognized-flags'], | |
| 72 perf = args['perf'], | 82 perf = args['perf'], |
| 83 shouldBatch = args['batch'], |
| 73 showPackageWarnings = args['show-package-warnings'] || args['package-warni
ngs'], | 84 showPackageWarnings = args['show-package-warnings'] || args['package-warni
ngs'], |
| 74 showSdkWarnings = args['show-sdk-warnings'] || args['warnings'], | 85 showSdkWarnings = args['show-sdk-warnings'] || args['warnings'], |
| 86 sourceFiles = args.rest, |
| 75 warmPerf = args['warm-perf'], | 87 warmPerf = args['warm-perf'], |
| 76 warningsAreFatal = args['fatal-warnings'], | 88 warningsAreFatal = args['fatal-warnings']; |
| 77 dartSdkPath = args['dart-sdk'], | |
| 78 packageRootPath = args['package-root'], | |
| 79 log = args['log'], | |
| 80 sourceFiles = args.rest, | |
| 81 this.definedVariables = definedVariables; | |
| 82 | 89 |
| 83 /** | 90 /** |
| 84 * Parse [args] into [CommandLineOptions] describing the specified | 91 * Parse [args] into [CommandLineOptions] describing the specified |
| 85 * analyzer options. In case of a format error, prints error and exists. | 92 * analyzer options. In case of a format error, prints error and exists. |
| 86 */ | 93 */ |
| 87 static CommandLineOptions parse(List<String> args) { | 94 static CommandLineOptions parse(List<String> args) { |
| 88 CommandLineOptions options = _parse(args); | 95 CommandLineOptions options = _parse(args); |
| 89 // check SDK | 96 // check SDK |
| 90 { | 97 { |
| 91 var sdkPath = options.dartSdkPath; | 98 var sdkPath = options.dartSdkPath; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 defaultsTo: false, negatable: false) | 135 defaultsTo: false, negatable: false) |
| 129 ..addFlag('package-warnings', | 136 ..addFlag('package-warnings', |
| 130 help: 'Show warnings from package: imports', | 137 help: 'Show warnings from package: imports', |
| 131 defaultsTo: false, negatable: false) | 138 defaultsTo: false, negatable: false) |
| 132 ..addFlag('show-package-warnings', | 139 ..addFlag('show-package-warnings', |
| 133 help: 'Show warnings from package: imports (deprecated)', | 140 help: 'Show warnings from package: imports (deprecated)', |
| 134 defaultsTo: false, negatable: false) | 141 defaultsTo: false, negatable: false) |
| 135 ..addFlag('perf', | 142 ..addFlag('perf', |
| 136 help: 'Show performance statistics', | 143 help: 'Show performance statistics', |
| 137 defaultsTo: false, negatable: false) | 144 defaultsTo: false, negatable: false) |
| 138 ..addFlag('warm-perf', | |
| 139 help: 'Show both cold and warm performance statistics', | |
| 140 defaultsTo: false, negatable: false, hide: true) | |
| 141 ..addFlag('warnings', help: 'Show warnings from SDK imports', | 145 ..addFlag('warnings', help: 'Show warnings from SDK imports', |
| 142 defaultsTo: false, negatable: false) | 146 defaultsTo: false, negatable: false) |
| 143 ..addFlag('show-sdk-warnings', help: 'Show warnings from SDK imports (depr
ecated)', | 147 ..addFlag('show-sdk-warnings', help: 'Show warnings from SDK imports (depr
ecated)', |
| 144 defaultsTo: false, negatable: false) | 148 defaultsTo: false, negatable: false) |
| 145 ..addFlag('help', abbr: 'h', help: 'Display this help message', | 149 ..addFlag('help', abbr: 'h', help: 'Display this help message', |
| 146 defaultsTo: false, negatable: false) | 150 defaultsTo: false, negatable: false) |
| 151 // |
| 152 // Hidden flags. |
| 153 // |
| 154 ..addFlag('enable-async', |
| 155 help: 'Enable support for the proposed async feature', |
| 156 defaultsTo: false, negatable: false, hide: true) |
| 157 ..addFlag('enable-enum', |
| 158 help: 'Enable support for the proposed enum feature', |
| 159 defaultsTo: false, negatable: false, hide: true) |
| 147 ..addFlag('log', help: 'Log additional messages and exceptions', | 160 ..addFlag('log', help: 'Log additional messages and exceptions', |
| 148 defaultsTo: false, negatable: false, hide: true); | 161 defaultsTo: false, negatable: false, hide: true) |
| 162 ..addFlag('warm-perf', |
| 163 help: 'Show both cold and warm performance statistics', |
| 164 defaultsTo: false, negatable: false, hide: true); |
| 149 | 165 |
| 150 try { | 166 try { |
| 151 // TODO(scheglov) https://code.google.com/p/dart/issues/detail?id=11061 | 167 // TODO(scheglov) https://code.google.com/p/dart/issues/detail?id=11061 |
| 152 args = args.map((String arg) => arg == '-batch' ? '--batch' : arg).toList(
); | 168 args = args.map((String arg) => arg == '-batch' ? '--batch' : arg).toList(
); |
| 153 Map<String, String> definedVariables = <String, String>{}; | 169 Map<String, String> definedVariables = <String, String>{}; |
| 154 var results = parser.parse(args, definedVariables); | 170 var results = parser.parse(args, definedVariables); |
| 155 // help requests | 171 // help requests |
| 156 if (results['help']) { | 172 if (results['help']) { |
| 157 _showUsage(parser); | 173 _showUsage(parser); |
| 158 exit(0); | 174 exit(0); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 | 330 |
| 315 _getNextFlagIndex(args, i) { | 331 _getNextFlagIndex(args, i) { |
| 316 for ( ; i < args.length; ++i) { | 332 for ( ; i < args.length; ++i) { |
| 317 if (args[i].startsWith('--')) { | 333 if (args[i].startsWith('--')) { |
| 318 return i; | 334 return i; |
| 319 } | 335 } |
| 320 } | 336 } |
| 321 return i; | 337 return i; |
| 322 } | 338 } |
| 323 } | 339 } |
| OLD | NEW |