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

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

Issue 2692203010: Remove older deprecated flags; more cleanup to the cli help args. (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
« no previous file with comments | « pkg/analyzer_cli/README.md ('k') | pkg/analyzer_cli/test/driver_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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';
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 /// speed at the expense of memory usage. It may also be useful for working 80 /// speed at the expense of memory usage. It may also be useful for working
81 /// around bugs. 81 /// around bugs.
82 final bool disableCacheFlushing; 82 final bool disableCacheFlushing;
83 83
84 /// Whether to report hints 84 /// Whether to report hints
85 final bool disableHints; 85 final bool disableHints;
86 86
87 /// Whether to display version information 87 /// Whether to display version information
88 final bool displayVersion; 88 final bool displayVersion;
89 89
90 /// Whether to enable null-aware operators (DEP 9).
91 final bool enableNullAwareOperators;
92
93 /// Whether to treat type mismatches found during constant evaluation as 90 /// Whether to treat type mismatches found during constant evaluation as
94 /// errors. 91 /// errors.
95 final bool enableTypeChecks; 92 final bool enableTypeChecks;
96 93
97 /// Whether to treat hints as fatal 94 /// Whether to treat hints as fatal
98 final bool hintsAreFatal; 95 final bool hintsAreFatal;
99 96
100 /// Whether to ignore unrecognized flags 97 /// Whether to ignore unrecognized flags
101 final bool ignoreUnrecognizedFlags; 98 final bool ignoreUnrecognizedFlags;
102 99
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 args['build-summary-exclude-informative'], 155 args['build-summary-exclude-informative'],
159 buildSummaryOutput = args['build-summary-output'], 156 buildSummaryOutput = args['build-summary-output'],
160 buildSummaryOutputSemantic = args['build-summary-output-semantic'], 157 buildSummaryOutputSemantic = args['build-summary-output-semantic'],
161 buildSuppressExitCode = args['build-suppress-exit-code'], 158 buildSuppressExitCode = args['build-suppress-exit-code'],
162 contextBuilderOptions = createContextBuilderOptions(args), 159 contextBuilderOptions = createContextBuilderOptions(args),
163 dartSdkPath = args['dart-sdk'], 160 dartSdkPath = args['dart-sdk'],
164 dartSdkSummaryPath = args['dart-sdk-summary'], 161 dartSdkSummaryPath = args['dart-sdk-summary'],
165 disableCacheFlushing = args['disable-cache-flushing'], 162 disableCacheFlushing = args['disable-cache-flushing'],
166 disableHints = args['no-hints'], 163 disableHints = args['no-hints'],
167 displayVersion = args['version'], 164 displayVersion = args['version'],
168 enableNullAwareOperators = args['enable-null-aware-operators'],
169 enableTypeChecks = args['enable_type_checks'], 165 enableTypeChecks = args['enable_type_checks'],
170 hintsAreFatal = args['fatal-hints'], 166 hintsAreFatal = args['fatal-hints'],
171 ignoreUnrecognizedFlags = args['ignore-unrecognized-flags'], 167 ignoreUnrecognizedFlags = args['ignore-unrecognized-flags'],
172 lints = args['lints'], 168 lints = args['lints'],
173 log = args['log'], 169 log = args['log'],
174 machineFormat = args['machine'] || args['format'] == 'machine', 170 machineFormat = args['format'] == 'machine',
175 perfReport = args['x-perf-report'], 171 perfReport = args['x-perf-report'],
176 shouldBatch = args['batch'], 172 shouldBatch = args['batch'],
177 showPackageWarnings = args['show-package-warnings'] || 173 showPackageWarnings = args['show-package-warnings'] ||
178 args['package-warnings'] || 174 args['package-warnings'] ||
179 args['x-package-warnings-prefix'] != null, 175 args['x-package-warnings-prefix'] != null,
180 showPackageWarningsPrefix = args['x-package-warnings-prefix'], 176 showPackageWarningsPrefix = args['x-package-warnings-prefix'],
181 showSdkWarnings = args['show-sdk-warnings'] || args['warnings'], 177 showSdkWarnings = args['show-sdk-warnings'] || args['warnings'],
182 sourceFiles = args.rest, 178 sourceFiles = args.rest,
183 warningsAreFatal = args['fatal-warnings'], 179 warningsAreFatal = args['fatal-warnings'],
184 strongMode = args['strong'], 180 strongMode = args['strong'],
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 // Check SDK. 217 // Check SDK.
222 if (!options.buildModePersistentWorker) { 218 if (!options.buildModePersistentWorker) {
223 // Infer if unspecified. 219 // Infer if unspecified.
224 if (options.dartSdkPath == null) { 220 if (options.dartSdkPath == null) {
225 Directory sdkDir = getSdkDir(args); 221 Directory sdkDir = getSdkDir(args);
226 if (sdkDir != null) { 222 if (sdkDir != null) {
227 options.dartSdkPath = sdkDir.path; 223 options.dartSdkPath = sdkDir.path;
228 } 224 }
229 } 225 }
230 226
231 var sdkPath = options.dartSdkPath; 227 String sdkPath = options.dartSdkPath;
232 228
233 // Check that SDK is specified. 229 // Check that SDK is specified.
234 if (sdkPath == null) { 230 if (sdkPath == null) {
235 printAndFail('No Dart SDK found.'); 231 printAndFail('No Dart SDK found.');
236 return null; // Only reachable in testing. 232 return null; // Only reachable in testing.
237 } 233 }
238 // Check that SDK is existing directory. 234 // Check that SDK is existing directory.
239 if (!(new Directory(sdkPath)).existsSync()) { 235 if (!(new Directory(sdkPath)).existsSync()) {
240 printAndFail('Invalid Dart SDK path: $sdkPath'); 236 printAndFail('Invalid Dart SDK path: $sdkPath');
241 return null; // Only reachable in testing. 237 return null; // Only reachable in testing.
242 } 238 }
243 } 239 }
244 240
245 // Check package config. 241 // Check package config.
246 { 242 {
247 if (options.packageRootPath != null && 243 if (options.packageRootPath != null &&
248 options.packageConfigPath != null) { 244 options.packageConfigPath != null) {
249 printAndFail("Cannot specify both '--package-root' and '--packages."); 245 printAndFail("Cannot specify both '--package-root' and '--packages.");
250 return null; // Only reachable in testing. 246 return null; // Only reachable in testing.
251 } 247 }
252 } 248 }
253 249
254 // OK. Report deprecated options.
255 if (options.enableNullAwareOperators) {
256 errorSink.writeln(
257 "Info: Option '--enable-null-aware-operators' is no longer needed. "
258 "Null aware operators are supported by default.");
259 }
260
261 // Build mode. 250 // Build mode.
262 if (options.buildModePersistentWorker && !options.buildMode) { 251 if (options.buildModePersistentWorker && !options.buildMode) {
263 printAndFail('The option --persisten_worker can be used only ' 252 printAndFail('The option --persisten_worker can be used only '
264 'together with --build-mode.'); 253 'together with --build-mode.');
265 } 254 }
266 if (options.buildSummaryOnlyDiet && !options.buildSummaryOnly) { 255 if (options.buildSummaryOnlyDiet && !options.buildSummaryOnly) {
267 printAndFail('The option --build-summary-only-diet can be used only ' 256 printAndFail('The option --build-summary-only-diet can be used only '
268 'together with --build-summary-only.'); 257 'together with --build-summary-only.');
269 } 258 }
270 259
(...skipping 12 matching lines...) Expand all
283 return "<unknown>"; 272 return "<unknown>";
284 } 273 }
285 } 274 }
286 275
287 static CommandLineOptions _parse(List<String> args) { 276 static CommandLineOptions _parse(List<String> args) {
288 args = preprocessArgs(PhysicalResourceProvider.INSTANCE, args); 277 args = preprocessArgs(PhysicalResourceProvider.INSTANCE, args);
289 278
290 bool verbose = args.contains('-v') || args.contains('--verbose'); 279 bool verbose = args.contains('-v') || args.contains('--verbose');
291 bool hide = !verbose; 280 bool hide = !verbose;
292 281
293 var parser = new ArgParser(allowTrailingOptions: true); 282 ArgParser parser = new ArgParser(allowTrailingOptions: true);
283
284 if (!hide) {
285 parser.addSeparator('General options:');
286 }
287
288 // TODO(devoncarew): This defines some hidden flags, which would be better
289 // defined with the rest of the hidden flags below (to group well with the
290 // other flags).
294 defineAnalysisArguments(parser, hide: hide); 291 defineAnalysisArguments(parser, hide: hide);
292
295 parser 293 parser
296 ..addOption('format', 294 ..addOption('format',
297 help: 295 help: 'Specifies the format in which errors are displayed; the only '
298 'Specifies the format in which errors are displayed. The only curr ently allowed value is \'machine\'.') 296 'currently allowed value is \'machine\'.')
299 ..addFlag('version', 297 ..addFlag('version',
300 help: 'Print the analyzer version.', 298 help: 'Print the analyzer version.',
301 defaultsTo: false, 299 defaultsTo: false,
302 negatable: false) 300 negatable: false)
303 ..addFlag('lints', 301 ..addFlag('lints',
304 help: 'Show lint results.', defaultsTo: false, negatable: false) 302 help: 'Show lint results.', defaultsTo: false, negatable: false)
305 ..addFlag('no-hints', 303 ..addFlag('no-hints',
306 help: 'Do not show hint results.', 304 help: 'Do not show hint results.',
307 defaultsTo: false, 305 defaultsTo: false,
308 negatable: false) 306 negatable: false)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 ..addFlag('verbose', 341 ..addFlag('verbose',
344 abbr: 'v', 342 abbr: 'v',
345 defaultsTo: false, 343 defaultsTo: false,
346 help: 'Verbose output.', 344 help: 'Verbose output.',
347 negatable: false) 345 negatable: false)
348 ..addOption('url-mapping', 346 ..addOption('url-mapping',
349 help: '--url-mapping=libraryUri,/path/to/library.dart directs the ' 347 help: '--url-mapping=libraryUri,/path/to/library.dart directs the '
350 'analyzer to use "library.dart" as the source for an import ' 348 'analyzer to use "library.dart" as the source for an import '
351 'of "libraryUri".', 349 'of "libraryUri".',
352 allowMultiple: true, 350 allowMultiple: true,
353 splitCommas: false) 351 splitCommas: false);
354 352
355 // 353 // Build mode options.
356 // Build mode. 354 if (!hide) {
357 // 355 parser.addSeparator('Build mode flags:');
356 }
357
358 parser
358 ..addFlag('persistent_worker', 359 ..addFlag('persistent_worker',
359 help: 'Enable Bazel persistent worker mode.', 360 help: 'Enable Bazel persistent worker mode.',
360 defaultsTo: false, 361 defaultsTo: false,
361 negatable: false, 362 negatable: false,
362 hide: hide) 363 hide: hide)
363 ..addOption('build-analysis-output', 364 ..addOption('build-analysis-output',
364 help: 365 help:
365 'Specifies the path to the file where analysis results should be w ritten.', 366 'Specifies the path to the file where analysis results should be w ritten.',
366 hide: hide) 367 hide: hide)
367 ..addFlag('build-mode', 368 ..addFlag('build-mode',
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 ..addFlag('build-summary-exclude-informative', 402 ..addFlag('build-summary-exclude-informative',
402 help: 'Exclude @informative information (docs, offsets, etc). ' 403 help: 'Exclude @informative information (docs, offsets, etc). '
403 'Deprecated: please use --build-summary-output-semantic instead.', 404 'Deprecated: please use --build-summary-output-semantic instead.',
404 defaultsTo: false, 405 defaultsTo: false,
405 negatable: false, 406 negatable: false,
406 hide: hide) 407 hide: hide)
407 ..addFlag('build-suppress-exit-code', 408 ..addFlag('build-suppress-exit-code',
408 help: 'Exit with code 0 even if errors are found.', 409 help: 'Exit with code 0 even if errors are found.',
409 defaultsTo: false, 410 defaultsTo: false,
410 negatable: false, 411 negatable: false,
411 hide: hide) 412 hide: hide);
412 413
413 // 414 // Hidden flags.
414 // Hidden flags. 415 if (!hide) {
415 // 416 parser.addSeparator('Less frequently used flags:');
416 ..addFlag('machine', 417 }
417 help: 'Print errors in a format suitable for parsing (deprecated).', 418
418 defaultsTo: false, 419 parser
419 negatable: false,
420 hide: hide)
421 ..addFlag('batch', 420 ..addFlag('batch',
422 help: 'Read commands from standard input (for testing).', 421 help: 'Read commands from standard input (for testing).',
423 defaultsTo: false, 422 defaultsTo: false,
424 negatable: false, 423 negatable: false,
425 hide: hide) 424 hide: hide)
426 ..addFlag('disable-cache-flushing', defaultsTo: false, hide: hide) 425 ..addFlag('disable-cache-flushing', defaultsTo: false, hide: hide)
427 ..addOption('x-perf-report', 426 ..addOption('x-perf-report',
428 help: 'Writes a performance report to the given file (experimental).', 427 help: 'Writes a performance report to the given file (experimental).',
429 hide: hide) 428 hide: hide)
430 ..addOption('x-package-warnings-prefix', 429 ..addOption('x-package-warnings-prefix',
431 help: 430 help:
432 'Show warnings from package: imports that match the given prefix', 431 'Show warnings from package: imports that match the given prefix',
433 hide: hide) 432 hide: hide)
434 ..addFlag('enable-conditional-directives', 433 ..addFlag('enable-conditional-directives',
435 help: 434 help:
436 'deprecated -- Enable support for conditional directives (DEP 40). ', 435 'deprecated -- Enable support for conditional directives (DEP 40). ',
437 defaultsTo: false, 436 defaultsTo: false,
438 negatable: false, 437 negatable: false,
439 hide: hide) 438 hide: hide)
440 ..addFlag('enable-null-aware-operators',
441 help: 'Enable support for null-aware operators (DEP 9).',
442 defaultsTo: false,
443 negatable: false,
444 hide: hide)
445 ..addFlag('enable-new-task-model',
446 help: 'deprecated -- Ennable new task model.',
447 defaultsTo: false,
448 negatable: false,
449 hide: hide)
450 ..addFlag('log', 439 ..addFlag('log',
451 help: 'Log additional messages and exceptions.', 440 help: 'Log additional messages and exceptions.',
452 defaultsTo: false, 441 defaultsTo: false,
453 negatable: false, 442 negatable: false,
454 hide: hide) 443 hide: hide)
455 ..addFlag('enable_type_checks', 444 ..addFlag('enable_type_checks',
456 help: 'Check types in constant evaluation.', 445 help: 'Check types in constant evaluation.',
457 defaultsTo: false, 446 defaultsTo: false,
458 negatable: false, 447 negatable: false,
459 hide: hide) 448 hide: hide)
460 ..addFlag('use-analysis-driver-memory-byte-store', 449 ..addFlag('use-analysis-driver-memory-byte-store',
461 help: 'Use memory byte store, not the file system cache.', 450 help: 'Use memory byte store, not the file system cache.',
462 defaultsTo: false, 451 defaultsTo: false,
463 negatable: false, 452 negatable: false,
464 hide: hide); 453 hide: hide);
465 454
466 try { 455 try {
467 if (args.contains('--$ignoreUnrecognizedFlagsFlag')) { 456 if (args.contains('--$ignoreUnrecognizedFlagsFlag')) {
468 args = filterUnknownArguments(args, parser); 457 args = filterUnknownArguments(args, parser);
469 } 458 }
470 var results = parser.parse(args); 459 ArgResults results = parser.parse(args);
471 460
472 // Persistent worker. 461 // Persistent worker.
473 if (args.contains('--persistent_worker')) { 462 if (args.contains('--persistent_worker')) {
474 bool validArgs; 463 bool validArgs;
475 if (!args.contains('--build-mode')) { 464 if (!args.contains('--build-mode')) {
476 validArgs = false; 465 validArgs = false;
477 } else if (args.length == 2) { 466 } else if (args.length == 2) {
478 validArgs = true; 467 validArgs = true;
479 } else if (args.length == 4 && args.contains('--dart-sdk')) { 468 } else if (args.length == 4 && args.contains('--dart-sdk')) {
480 validArgs = true; 469 validArgs = true;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 } 514 }
526 return new CommandLineOptions._fromArgs(results); 515 return new CommandLineOptions._fromArgs(results);
527 } on FormatException catch (e) { 516 } on FormatException catch (e) {
528 errorSink.writeln(e.message); 517 errorSink.writeln(e.message);
529 _showUsage(parser); 518 _showUsage(parser);
530 exitHandler(15); 519 exitHandler(15);
531 return null; // Only reachable in testing. 520 return null; // Only reachable in testing.
532 } 521 }
533 } 522 }
534 523
535 static _showUsage(parser) { 524 static _showUsage(ArgParser parser) {
536 errorSink 525 errorSink.writeln(
537 .writeln('Usage: $_binaryName [options...] <libraries to analyze...>'); 526 'Usage: $_binaryName [options...] <directory or list of files>');
538 errorSink.writeln(parser.getUsage());
539 errorSink.writeln(''); 527 errorSink.writeln('');
540 errorSink.writeln( 528 errorSink.writeln(parser.usage);
541 'For more information, see http://www.dartlang.org/tools/analyzer.'); 529 errorSink.writeln('');
530 errorSink.writeln('''
531 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.
533 ''');
542 } 534 }
543 } 535 }
OLDNEW
« no previous file with comments | « pkg/analyzer_cli/README.md ('k') | pkg/analyzer_cli/test/driver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698