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

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

Issue 2571583007: move extractDefinedVariables from analyzer cli to analyzer (Closed)
Patch Set: add TODO indicating future work Created 4 years 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';
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 help: 'Disable implicit casts in strong mode (https://goo.gl/cTLz40)') 484 help: 'Disable implicit casts in strong mode (https://goo.gl/cTLz40)')
485 ..addFlag('no-implicit-dynamic', 485 ..addFlag('no-implicit-dynamic',
486 negatable: false, 486 negatable: false,
487 help: 'Disable implicit dynamic (https://goo.gl/m0UgXD)'); 487 help: 'Disable implicit dynamic (https://goo.gl/m0UgXD)');
488 488
489 try { 489 try {
490 // TODO(scheglov) https://code.google.com/p/dart/issues/detail?id=11061 490 // TODO(scheglov) https://code.google.com/p/dart/issues/detail?id=11061
491 args = 491 args =
492 args.map((String arg) => arg == '-batch' ? '--batch' : arg).toList(); 492 args.map((String arg) => arg == '-batch' ? '--batch' : arg).toList();
493 Map<String, String> definedVariables = <String, String>{}; 493 Map<String, String> definedVariables = <String, String>{};
494 var results = parser.parse(args, definedVariables); 494 args = extractDefinedVariables(args, definedVariables);
495 var results = parser.parse(args);
495 496
496 // Persistent worker. 497 // Persistent worker.
497 if (args.contains('--persistent_worker')) { 498 if (args.contains('--persistent_worker')) {
498 bool validArgs; 499 bool validArgs;
499 if (!args.contains('--build-mode')) { 500 if (!args.contains('--build-mode')) {
500 validArgs = false; 501 validArgs = false;
501 } else if (args.length == 2) { 502 } else if (args.length == 2) {
502 validArgs = true; 503 validArgs = true;
503 } else if (args.length == 4 && args.contains('--dart-sdk')) { 504 } else if (args.length == 4 && args.contains('--dart-sdk')) {
504 validArgs = true; 505 validArgs = true;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 allowMultiple: allowMultiple, 627 allowMultiple: allowMultiple,
627 splitCommas: splitCommas, 628 splitCommas: splitCommas,
628 hide: hide); 629 hide: hide);
629 } 630 }
630 631
631 /// Generates a string displaying usage information for the defined options. 632 /// Generates a string displaying usage information for the defined options.
632 /// See [ArgParser.usage]. 633 /// See [ArgParser.usage].
633 String getUsage() => _parser.usage; 634 String getUsage() => _parser.usage;
634 635
635 /// Parses [args], a list of command-line arguments, matches them against the 636 /// Parses [args], a list of command-line arguments, matches them against the
636 /// flags and options defined by this parser, and returns the result. The 637 /// flags and options defined by this parser, and returns the result.
637 /// values of any defined variables are captured in the given map.
638 /// See [ArgParser]. 638 /// See [ArgParser].
639 ArgResults parse(List<String> args, Map<String, String> definedVariables) => 639 ArgResults parse(List<String> args) => _parser.parse(_filterUnknowns(args));
640 _parser.parse(
641 _filterUnknowns(parseDefinedVariables(args, definedVariables)));
642
643 List<String> parseDefinedVariables(
644 List<String> args, Map<String, String> definedVariables) {
645 int count = args.length;
646 List<String> remainingArgs = <String>[];
647 for (int i = 0; i < count; i++) {
648 String arg = args[i];
649 if (arg == '--') {
650 while (i < count) {
651 remainingArgs.add(args[i++]);
652 }
653 } else if (arg.startsWith("-D")) {
654 definedVariables[arg.substring(2)] = args[++i];
655 } else {
656 remainingArgs.add(arg);
657 }
658 }
659 return remainingArgs;
660 }
661 640
662 List<String> _filterUnknowns(List<String> args) { 641 List<String> _filterUnknowns(List<String> args) {
663 // Only filter args if the ignore flag is specified, or if 642 // Only filter args if the ignore flag is specified, or if
664 // _alwaysIgnoreUnrecognized was set to true. 643 // _alwaysIgnoreUnrecognized was set to true.
665 if (_alwaysIgnoreUnrecognized || 644 if (_alwaysIgnoreUnrecognized ||
666 args.contains('--ignore-unrecognized-flags')) { 645 args.contains('--ignore-unrecognized-flags')) {
667 //TODO(pquitslund): replace w/ the following once library skew issues are 646 //TODO(pquitslund): replace w/ the following once library skew issues are
668 // sorted out 647 // sorted out
669 //return args.where((arg) => !arg.startsWith('--') || 648 //return args.where((arg) => !arg.startsWith('--') ||
670 // _knownFlags.contains(arg.substring(2))); 649 // _knownFlags.contains(arg.substring(2)));
(...skipping 29 matching lines...) Expand all
700 679
701 int _getNextFlagIndex(args, i) { 680 int _getNextFlagIndex(args, i) {
702 for (; i < args.length; ++i) { 681 for (; i < args.length; ++i) {
703 if (args[i].startsWith('--')) { 682 if (args[i].startsWith('--')) {
704 return i; 683 return i;
705 } 684 }
706 } 685 }
707 return i; 686 return i;
708 } 687 }
709 } 688 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/src/command_line/arguments_test.dart ('k') | pkg/analyzer_cli/test/options_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698