| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 | 44 |
| 45 /** The path to the dart SDK */ | 45 /** The path to the dart SDK */ |
| 46 final String dartSdkPath; | 46 final String dartSdkPath; |
| 47 | 47 |
| 48 /** The path to the package root */ | 48 /** The path to the package root */ |
| 49 final String packageRootPath; | 49 final String packageRootPath; |
| 50 | 50 |
| 51 /** The source files to analyze */ | 51 /** The source files to analyze */ |
| 52 final List<String> sourceFiles; | 52 final List<String> sourceFiles; |
| 53 | 53 |
| 54 /** Whether to log additional analysis messages and exceptions */ |
| 55 final bool log; |
| 56 |
| 54 /** | 57 /** |
| 55 * Initialize options from the given parsed [args]. | 58 * Initialize options from the given parsed [args]. |
| 56 */ | 59 */ |
| 57 CommandLineOptions._fromArgs(ArgResults args) | 60 CommandLineOptions._fromArgs(ArgResults args) |
| 58 : shouldBatch = args['batch'], | 61 : shouldBatch = args['batch'], |
| 59 machineFormat = args['machine'] || args['format'] == 'machine', | 62 machineFormat = args['machine'] || args['format'] == 'machine', |
| 60 displayVersion = args['version'], | 63 displayVersion = args['version'], |
| 61 disableHints = args['no-hints'], | 64 disableHints = args['no-hints'], |
| 62 ignoreUnrecognizedFlags = args['ignore-unrecognized-flags'], | 65 ignoreUnrecognizedFlags = args['ignore-unrecognized-flags'], |
| 63 perf = args['perf'], | 66 perf = args['perf'], |
| 64 showPackageWarnings = args['show-package-warnings'] || args['package-warni
ngs'], | 67 showPackageWarnings = args['show-package-warnings'] || args['package-warni
ngs'], |
| 65 showSdkWarnings = args['show-sdk-warnings'] || args['warnings'], | 68 showSdkWarnings = args['show-sdk-warnings'] || args['warnings'], |
| 66 warningsAreFatal = args['fatal-warnings'], | 69 warningsAreFatal = args['fatal-warnings'], |
| 67 dartSdkPath = args['dart-sdk'], | 70 dartSdkPath = args['dart-sdk'], |
| 68 packageRootPath = args['package-root'], | 71 packageRootPath = args['package-root'], |
| 72 log = args['log'], |
| 69 sourceFiles = args.rest; | 73 sourceFiles = args.rest; |
| 70 | 74 |
| 71 /** | 75 /** |
| 72 * Parse [args] into [CommandLineOptions] describing the specified | 76 * Parse [args] into [CommandLineOptions] describing the specified |
| 73 * analyzer options. In case of a format error, prints error and exists. | 77 * analyzer options. In case of a format error, prints error and exists. |
| 74 */ | 78 */ |
| 75 static CommandLineOptions parse(List<String> args) { | 79 static CommandLineOptions parse(List<String> args) { |
| 76 CommandLineOptions options = _parse(args); | 80 CommandLineOptions options = _parse(args); |
| 77 // check SDK | 81 // check SDK |
| 78 { | 82 { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 help: 'Show warnings from package: imports (deprecated)', | 125 help: 'Show warnings from package: imports (deprecated)', |
| 122 defaultsTo: false, negatable: false) | 126 defaultsTo: false, negatable: false) |
| 123 ..addFlag('perf', | 127 ..addFlag('perf', |
| 124 help: 'Show performance statistics', | 128 help: 'Show performance statistics', |
| 125 defaultsTo: false, negatable: false) | 129 defaultsTo: false, negatable: false) |
| 126 ..addFlag('warnings', help: 'Show warnings from SDK imports', | 130 ..addFlag('warnings', help: 'Show warnings from SDK imports', |
| 127 defaultsTo: false, negatable: false) | 131 defaultsTo: false, negatable: false) |
| 128 ..addFlag('show-sdk-warnings', help: 'Show warnings from SDK imports (depr
ecated)', | 132 ..addFlag('show-sdk-warnings', help: 'Show warnings from SDK imports (depr
ecated)', |
| 129 defaultsTo: false, negatable: false) | 133 defaultsTo: false, negatable: false) |
| 130 ..addFlag('help', abbr: 'h', help: 'Display this help message', | 134 ..addFlag('help', abbr: 'h', help: 'Display this help message', |
| 131 defaultsTo: false, negatable: false); | 135 defaultsTo: false, negatable: false) |
| 136 ..addFlag('log', help: 'Log additional messages and exceptions', |
| 137 defaultsTo: false, negatable: false, hide: true); |
| 132 | 138 |
| 133 try { | 139 try { |
| 134 // TODO(scheglov) https://code.google.com/p/dart/issues/detail?id=11061 | 140 // TODO(scheglov) https://code.google.com/p/dart/issues/detail?id=11061 |
| 135 args = args.map((String arg) => arg == '-batch' ? '--batch' : arg).toList(
); | 141 args = args.map((String arg) => arg == '-batch' ? '--batch' : arg).toList(
); |
| 136 var results = parser.parse(args); | 142 var results = parser.parse(args); |
| 137 // help requests | 143 // help requests |
| 138 if (results['help']) { | 144 if (results['help']) { |
| 139 _showUsage(parser); | 145 _showUsage(parser); |
| 140 exit(0); | 146 exit(0); |
| 141 } | 147 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 : _knownFlags = <String>[], | 205 : _knownFlags = <String>[], |
| 200 _parser = new ArgParser(); | 206 _parser = new ArgParser(); |
| 201 | 207 |
| 202 | 208 |
| 203 /** | 209 /** |
| 204 * Defines a flag. | 210 * Defines a flag. |
| 205 * | 211 * |
| 206 * See [ArgParser.addFlag()]. | 212 * See [ArgParser.addFlag()]. |
| 207 */ | 213 */ |
| 208 void addFlag(String name, {String abbr, String help, bool defaultsTo: false, | 214 void addFlag(String name, {String abbr, String help, bool defaultsTo: false, |
| 209 bool negatable: true, void callback(bool value)}) { | 215 bool negatable: true, void callback(bool value), bool hide: false}) { |
| 210 _knownFlags.add(name); | 216 _knownFlags.add(name); |
| 211 _parser.addFlag(name, abbr: abbr, help: help, defaultsTo: defaultsTo, | 217 _parser.addFlag(name, abbr: abbr, help: help, defaultsTo: defaultsTo, |
| 212 negatable: negatable, callback: callback); | 218 negatable: negatable, callback: callback, hide: hide); |
| 213 } | 219 } |
| 214 | 220 |
| 215 /** | 221 /** |
| 216 * Defines a value-taking option. | 222 * Defines a value-taking option. |
| 217 * | 223 * |
| 218 * See [ArgParser.addOption()]. | 224 * See [ArgParser.addOption()]. |
| 219 */ | 225 */ |
| 220 void addOption(String name, {String abbr, String help, List<String> allowed, | 226 void addOption(String name, {String abbr, String help, List<String> allowed, |
| 221 Map<String, String> allowedHelp, String defaultsTo, | 227 Map<String, String> allowedHelp, String defaultsTo, |
| 222 void callback(value), bool allowMultiple: false}) { | 228 void callback(value), bool allowMultiple: false}) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 | 281 |
| 276 _getNextFlagIndex(args, i) { | 282 _getNextFlagIndex(args, i) { |
| 277 for ( ; i < args.length; ++i) { | 283 for ( ; i < args.length; ++i) { |
| 278 if (args[i].startsWith('--')) { | 284 if (args[i].startsWith('--')) { |
| 279 return i; | 285 return i; |
| 280 } | 286 } |
| 281 } | 287 } |
| 282 return i; | 288 return i; |
| 283 } | 289 } |
| 284 } | 290 } |
| OLD | NEW |