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

Side by Side Diff: pkg/analyzer_cli/lib/src/options.dart

Issue 2704103002: Some improvements to the command-line analyzer's output. (Closed)
Patch Set: Created 3 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 analyzer_cli.src.options; 5 library analyzer_cli.src.options;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 8
9 import 'package:analyzer/file_system/physical_file_system.dart'; 9 import 'package:analyzer/file_system/physical_file_system.dart';
10 import 'package:analyzer/src/command_line/arguments.dart'; 10 import 'package:analyzer/src/command_line/arguments.dart';
11 import 'package:analyzer/src/context/builder.dart'; 11 import 'package:analyzer/src/context/builder.dart';
12 import 'package:analyzer_cli/src/driver.dart';
13 import 'package:args/args.dart'; 12 import 'package:args/args.dart';
14 import 'package:cli_util/cli_util.dart' show getSdkDir; 13 import 'package:cli_util/cli_util.dart' show getSdkDir;
15 14
15 import 'driver.dart';
16
16 const _binaryName = 'dartanalyzer'; 17 const _binaryName = 'dartanalyzer';
17 18
18 /// Shared exit handler. 19 /// Shared exit handler.
19 /// 20 ///
20 /// *Visible for testing.* 21 /// *Visible for testing.*
21 ExitHandler exitHandler = exit; 22 ExitHandler exitHandler = exit;
22 23
23 /// Print the given [message] to stderr and exit with the given [exitCode]. 24 /// Print the given [message] to stderr and exit with the given [exitCode].
24 void printAndFail(String message, {int exitCode: 15}) { 25 void printAndFail(String message, {int exitCode: 15}) {
25 errorSink.writeln(message); 26 errorSink.writeln(message);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 137
137 /// Whether implicit dynamic is enabled (mainly for strong mode users) 138 /// Whether implicit dynamic is enabled (mainly for strong mode users)
138 final bool implicitDynamic; 139 final bool implicitDynamic;
139 140
140 /// Whether to treat lints as fatal 141 /// Whether to treat lints as fatal
141 final bool lintsAreFatal; 142 final bool lintsAreFatal;
142 143
143 /// Whether to use memory byte store for analysis driver. 144 /// Whether to use memory byte store for analysis driver.
144 final bool useAnalysisDriverMemoryByteStore; 145 final bool useAnalysisDriverMemoryByteStore;
145 146
147 /// Emit output in a verbose mode.
148 final bool verbose;
149
146 /// Initialize options from the given parsed [args]. 150 /// Initialize options from the given parsed [args].
147 CommandLineOptions._fromArgs(ArgResults args) 151 CommandLineOptions._fromArgs(ArgResults args)
148 : buildAnalysisOutput = args['build-analysis-output'], 152 : buildAnalysisOutput = args['build-analysis-output'],
149 buildMode = args['build-mode'], 153 buildMode = args['build-mode'],
150 buildModePersistentWorker = args['persistent_worker'], 154 buildModePersistentWorker = args['persistent_worker'],
151 buildSummaryInputs = args['build-summary-input'] as List<String>, 155 buildSummaryInputs = args['build-summary-input'] as List<String>,
152 buildSummaryOnly = args['build-summary-only'], 156 buildSummaryOnly = args['build-summary-only'],
153 buildSummaryOnlyDiet = args['build-summary-only-diet'], 157 buildSummaryOnlyDiet = args['build-summary-only-diet'],
154 buildSummaryExcludeInformative = 158 buildSummaryExcludeInformative =
155 args['build-summary-exclude-informative'], 159 args['build-summary-exclude-informative'],
(...skipping 19 matching lines...) Expand all
175 args['x-package-warnings-prefix'] != null, 179 args['x-package-warnings-prefix'] != null,
176 showPackageWarningsPrefix = args['x-package-warnings-prefix'], 180 showPackageWarningsPrefix = args['x-package-warnings-prefix'],
177 showSdkWarnings = args['show-sdk-warnings'] || args['warnings'], 181 showSdkWarnings = args['show-sdk-warnings'] || args['warnings'],
178 sourceFiles = args.rest, 182 sourceFiles = args.rest,
179 warningsAreFatal = args['fatal-warnings'], 183 warningsAreFatal = args['fatal-warnings'],
180 strongMode = args['strong'], 184 strongMode = args['strong'],
181 implicitCasts = !args['no-implicit-casts'], 185 implicitCasts = !args['no-implicit-casts'],
182 implicitDynamic = !args['no-implicit-dynamic'], 186 implicitDynamic = !args['no-implicit-dynamic'],
183 lintsAreFatal = args['fatal-lints'], 187 lintsAreFatal = args['fatal-lints'],
184 useAnalysisDriverMemoryByteStore = 188 useAnalysisDriverMemoryByteStore =
185 args['use-analysis-driver-memory-byte-store']; 189 args['use-analysis-driver-memory-byte-store'],
190 verbose = args['verbose'];
186 191
187 /// The path to an analysis options file 192 /// The path to an analysis options file
188 String get analysisOptionsFile => 193 String get analysisOptionsFile =>
189 contextBuilderOptions.defaultAnalysisOptionsFilePath; 194 contextBuilderOptions.defaultAnalysisOptionsFilePath;
190 195
191 /// A table mapping the names of defined variables to their values. 196 /// A table mapping the names of defined variables to their values.
192 Map<String, String> get definedVariables => 197 Map<String, String> get definedVariables =>
193 contextBuilderOptions.declaredVariables; 198 contextBuilderOptions.declaredVariables;
194 199
195 /// Whether to strictly follow the specification when generating warnings on 200 /// Whether to strictly follow the specification when generating warnings on
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 ..addFlag('version', 302 ..addFlag('version',
298 help: 'Print the analyzer version.', 303 help: 'Print the analyzer version.',
299 defaultsTo: false, 304 defaultsTo: false,
300 negatable: false) 305 negatable: false)
301 ..addFlag('lints', 306 ..addFlag('lints',
302 help: 'Show lint results.', defaultsTo: false, negatable: false) 307 help: 'Show lint results.', defaultsTo: false, negatable: false)
303 ..addFlag('no-hints', 308 ..addFlag('no-hints',
304 help: 'Do not show hint results.', 309 help: 'Do not show hint results.',
305 defaultsTo: false, 310 defaultsTo: false,
306 negatable: false) 311 negatable: false)
307 ..addFlag(ignoreUnrecognizedFlagsFlag,
308 help: 'Ignore unrecognized command line flags.',
309 defaultsTo: false,
310 negatable: false)
311 ..addFlag('fatal-hints', 312 ..addFlag('fatal-hints',
312 help: 'Treat hints as fatal.', defaultsTo: false, negatable: false) 313 help: 'Treat hints as fatal.', defaultsTo: false, negatable: false)
313 ..addFlag('fatal-warnings', 314 ..addFlag('fatal-warnings',
314 help: 'Treat non-type warnings as fatal.', 315 help: 'Treat non-type warnings as fatal.',
315 defaultsTo: false, 316 defaultsTo: false,
316 negatable: false) 317 negatable: false)
317 ..addFlag('fatal-lints', 318 ..addFlag('fatal-lints',
318 help: 'Treat lints as fatal.', defaultsTo: false, negatable: false) 319 help: 'Treat lints as fatal.', defaultsTo: false, negatable: false)
319 ..addFlag('package-warnings', 320 ..addFlag('package-warnings',
320 help: 'Show warnings from package: imports.', 321 help: 'Show warnings from package: imports.',
(...skipping 14 matching lines...) Expand all
335 ..addFlag('help', 336 ..addFlag('help',
336 abbr: 'h', 337 abbr: 'h',
337 help: 338 help:
338 'Display this help message. Add --verbose to show hidden options.' , 339 'Display this help message. Add --verbose to show hidden options.' ,
339 defaultsTo: false, 340 defaultsTo: false,
340 negatable: false) 341 negatable: false)
341 ..addFlag('verbose', 342 ..addFlag('verbose',
342 abbr: 'v', 343 abbr: 'v',
343 defaultsTo: false, 344 defaultsTo: false,
344 help: 'Verbose output.', 345 help: 'Verbose output.',
345 negatable: false) 346 negatable: false);
346 ..addOption('url-mapping',
347 help: '--url-mapping=libraryUri,/path/to/library.dart directs the '
348 'analyzer to use "library.dart" as the source for an import '
349 'of "libraryUri".',
350 allowMultiple: true,
351 splitCommas: false);
352 347
353 // Build mode options. 348 // Build mode options.
354 if (!hide) { 349 if (!hide) {
355 parser.addSeparator('Build mode flags:'); 350 parser.addSeparator('Build mode flags:');
356 } 351 }
357 352
358 parser 353 parser
359 ..addFlag('persistent_worker', 354 ..addFlag('persistent_worker',
360 help: 'Enable Bazel persistent worker mode.', 355 help: 'Enable Bazel persistent worker mode.',
361 defaultsTo: false, 356 defaultsTo: false,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 if (!hide) { 410 if (!hide) {
416 parser.addSeparator('Less frequently used flags:'); 411 parser.addSeparator('Less frequently used flags:');
417 } 412 }
418 413
419 parser 414 parser
420 ..addFlag('batch', 415 ..addFlag('batch',
421 help: 'Read commands from standard input (for testing).', 416 help: 'Read commands from standard input (for testing).',
422 defaultsTo: false, 417 defaultsTo: false,
423 negatable: false, 418 negatable: false,
424 hide: hide) 419 hide: hide)
420 ..addFlag(ignoreUnrecognizedFlagsFlag,
421 help: 'Ignore unrecognized command line flags.',
422 defaultsTo: false,
423 negatable: false,
424 hide: hide)
425 ..addFlag('disable-cache-flushing', defaultsTo: false, hide: hide) 425 ..addFlag('disable-cache-flushing', defaultsTo: false, hide: hide)
426 ..addOption('x-perf-report', 426 ..addOption('x-perf-report',
427 help: 'Writes a performance report to the given file (experimental).', 427 help: 'Writes a performance report to the given file (experimental).',
428 hide: hide) 428 hide: hide)
429 ..addOption('x-package-warnings-prefix', 429 ..addOption('x-package-warnings-prefix',
430 help: 430 help:
431 'Show warnings from package: imports that match the given prefix', 431 'Show warnings from package: imports that match the given prefix',
432 hide: hide) 432 hide: hide)
433 ..addFlag('enable-conditional-directives', 433 ..addFlag('enable-conditional-directives',
434 help: 434 help:
435 'deprecated -- Enable support for conditional directives (DEP 40). ', 435 'deprecated -- Enable support for conditional directives (DEP 40). ',
436 defaultsTo: false, 436 defaultsTo: false,
437 negatable: false, 437 negatable: false,
438 hide: hide) 438 hide: hide)
439 ..addFlag('log', 439 ..addFlag('log',
440 help: 'Log additional messages and exceptions.', 440 help: 'Log additional messages and exceptions.',
441 defaultsTo: false, 441 defaultsTo: false,
442 negatable: false, 442 negatable: false,
443 hide: hide) 443 hide: hide)
444 ..addFlag('enable_type_checks', 444 ..addFlag('enable_type_checks',
445 help: 'Check types in constant evaluation.', 445 help: 'Check types in constant evaluation.',
446 defaultsTo: false, 446 defaultsTo: false,
447 negatable: false, 447 negatable: false,
448 hide: hide) 448 hide: hide)
449 ..addFlag('use-analysis-driver-memory-byte-store', 449 ..addFlag('use-analysis-driver-memory-byte-store',
450 help: 'Use memory byte store, not the file system cache.', 450 help: 'Use memory byte store, not the file system cache.',
451 defaultsTo: false, 451 defaultsTo: false,
452 negatable: false, 452 negatable: false,
453 hide: hide)
454 ..addOption('url-mapping',
455 help: '--url-mapping=libraryUri,/path/to/library.dart directs the '
456 'analyzer to use "library.dart" as the source for an import '
457 'of "libraryUri".',
458 allowMultiple: true,
459 splitCommas: false,
453 hide: hide); 460 hide: hide);
454 461
455 try { 462 try {
456 if (args.contains('--$ignoreUnrecognizedFlagsFlag')) { 463 if (args.contains('--$ignoreUnrecognizedFlagsFlag')) {
457 args = filterUnknownArguments(args, parser); 464 args = filterUnknownArguments(args, parser);
458 } 465 }
459 ArgResults results = parser.parse(args); 466 ArgResults results = parser.parse(args);
460 467
461 // Persistent worker. 468 // Persistent worker.
462 if (args.contains('--persistent_worker')) { 469 if (args.contains('--persistent_worker')) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 'Usage: $_binaryName [options...] <directory or list of files>'); 533 'Usage: $_binaryName [options...] <directory or list of files>');
527 errorSink.writeln(''); 534 errorSink.writeln('');
528 errorSink.writeln(parser.usage); 535 errorSink.writeln(parser.usage);
529 errorSink.writeln(''); 536 errorSink.writeln('');
530 errorSink.writeln(''' 537 errorSink.writeln('''
531 Run "dartanalyzer -h -v" for verbose help output, including less commonly used o ptions. 538 Run "dartanalyzer -h -v" for verbose help output, including less commonly used o ptions.
532 For more information, see http://www.dartlang.org/tools/analyzer. 539 For more information, see http://www.dartlang.org/tools/analyzer.
533 '''); 540 ''');
534 } 541 }
535 } 542 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698