Chromium Code Reviews| Index: pkg/analyzer_experimental/lib/options.dart |
| =================================================================== |
| --- pkg/analyzer_experimental/lib/options.dart (revision 23438) |
| +++ pkg/analyzer_experimental/lib/options.dart (working copy) |
| @@ -9,7 +9,7 @@ |
| import 'dart:io'; |
| -const _BINARY_NAME = 'analyzer'; |
| +const _BINARY_NAME = 'dartanalyzer'; |
| /** |
| * Analyzer commandline configuration options. |
| @@ -22,6 +22,9 @@ |
| /** Whether to use machine format for error display */ |
| final bool machineFormat; |
| + /** Whether to display version information */ |
| + final bool displayVersion; |
| + |
| /** Whether to ignore unrecognized flags */ |
| final bool ignoreUnrecognizedFlags; |
| @@ -48,7 +51,8 @@ |
| */ |
| CommandLineOptions._fromArgs(ArgResults args) |
| : shouldBatch = args['batch'], |
| - machineFormat = args['machine-format'], |
| + machineFormat = args['machine'], |
| + displayVersion = args['version'], |
| ignoreUnrecognizedFlags = args['ignore-unrecognized-flags'], |
| showPackageWarnings = args['show-package-warnings'], |
| showSdkWarnings = args['show-sdk-warnings'], |
| @@ -87,20 +91,23 @@ |
| defaultsTo: false, negatable: false) |
| ..addOption('dart-sdk', help: 'The path to the Dart SDK') |
| ..addOption('package-root', help: 'The path to the package root') |
| - ..addFlag('machine-format', help: 'Specify whether errors ' |
| - 'should be in machine format', |
| + ..addFlag('machine', |
| + help: 'Print errors in a format suitable for parsing', |
| defaultsTo: false, negatable: false) |
| + ..addFlag('version', help: 'Print the analyzer version', |
| + defaultsTo: false, negatable: false) |
| ..addFlag('ignore-unrecognized-flags', |
| help: 'Ignore unrecognized command line flags', |
| defaultsTo: false, negatable: false) |
| ..addFlag('fatal-warnings', help: 'Treat non-type warnings as fatal', |
| defaultsTo: false, negatable: false) |
| - ..addFlag('show-package-warnings', help: 'Show warnings from package: imports', |
| - defaultsTo: false, negatable: false) |
| + ..addFlag('show-package-warnings', |
| + help: 'Show warnings from package: imports', |
| + defaultsTo: false, negatable: false) |
| ..addFlag('show-sdk-warnings', help: 'Show warnings from SDK imports', |
| - defaultsTo: false, negatable: false) |
| + defaultsTo: false, negatable: false) |
| ..addFlag('help', abbr: 'h', help: 'Display this help message', |
| - defaultsTo: false, negatable: false); |
| + defaultsTo: false, negatable: false); |
| try { |
| var results = parser.parse(args); |
| @@ -116,6 +123,9 @@ |
| _showUsage(parser); |
| exit(15); |
| } |
| + } if (results['version']) { |
| + print('$_BINARY_NAME version ${_getVersion()}'); |
| + exit(0); |
| } else { |
| if (results.rest.length == 0) { |
| _showUsage(parser); |
| @@ -136,6 +146,18 @@ |
| print(parser.getUsage()); |
| } |
| + static String _getVersion() { |
| + try { |
| + Path path = new Path(new Options().script); |
| + Path versionPath = path.directoryPath.append('..').append('version'); |
| + File versionFile = new File.fromPath(versionPath); |
| + |
| + return versionFile.readAsStringSync().trim(); |
| + } catch (_) { |
| + // This happens when the script is not running out of an SDK. |
|
scheglov
2013/05/30 20:36:04
Unnecessary "not"?
devoncarew
2013/05/30 20:42:19
The exception is only thrown when the script is no
|
| + return "<unknown>"; |
| + } |
| + } |
| } |
| /** |