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

Unified Diff: pkg/analyzer/lib/options.dart

Issue 290733010: Parse defined variables in command-line analyzer (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/options_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/options.dart
diff --git a/pkg/analyzer/lib/options.dart b/pkg/analyzer/lib/options.dart
index 0922223ee8ea829effa7fcf43118f1a068dacab2..7dae073c1eb8205afbc9dc1c736ef9928d3d652a 100644
--- a/pkg/analyzer/lib/options.dart
+++ b/pkg/analyzer/lib/options.dart
@@ -24,6 +24,9 @@ class CommandLineOptions {
/** Whether to display version information */
final bool displayVersion;
+ /** A table mapping the names of defined variables to their values. */
+ final Map<String, String> definedVariables;
+
/** Whether to report hints */
final bool disableHints;
@@ -60,7 +63,7 @@ class CommandLineOptions {
/**
* Initialize options from the given parsed [args].
*/
- CommandLineOptions._fromArgs(ArgResults args)
+ CommandLineOptions._fromArgs(ArgResults args, Map<String, String> definedVariables)
: shouldBatch = args['batch'],
machineFormat = args['machine'] || args['format'] == 'machine',
displayVersion = args['version'],
@@ -74,7 +77,8 @@ class CommandLineOptions {
dartSdkPath = args['dart-sdk'],
packageRootPath = args['package-root'],
log = args['log'],
- sourceFiles = args.rest;
+ sourceFiles = args.rest,
+ this.definedVariables = definedVariables;
/**
* Parse [args] into [CommandLineOptions] describing the specified
@@ -146,7 +150,8 @@ class CommandLineOptions {
try {
// TODO(scheglov) https://code.google.com/p/dart/issues/detail?id=11061
args = args.map((String arg) => arg == '-batch' ? '--batch' : arg).toList();
- var results = parser.parse(args);
+ Map<String, String> definedVariables = <String, String>{};
pquitslund 2014/05/22 16:22:40 I think we want to lose the type annotation for co
+ var results = parser.parse(args, definedVariables);
// help requests
if (results['help']) {
_showUsage(parser);
@@ -168,7 +173,7 @@ class CommandLineOptions {
exit(15);
}
}
- return new CommandLineOptions._fromArgs(results);
+ return new CommandLineOptions._fromArgs(results, definedVariables);
} on FormatException catch (e) {
print(e.message);
_showUsage(parser);
@@ -249,11 +254,30 @@ class _CommandLineParser {
/**
* Parses [args], a list of command-line arguments, matches them against the
- * flags and options defined by this parser, and returns the result.
+ * flags and options defined by this parser, and returns the result. The
+ * values of any defined variables are captured in the given map.
*
* See [ArgParser].
*/
- ArgResults parse(List<String> args) => _parser.parse(_filterUnknowns(args));
+ ArgResults parse(List<String> args, Map<String, String> definedVariables) => _parser.parse(_filterUnknowns(parseDefinedVariables(args, definedVariables)));
+
+ List<String> parseDefinedVariables(List<String> args, Map<String, String> definedVariables) {
pquitslund 2014/05/22 16:22:40 This whole method should probably be cleansed of t
+ int count = args.length;
+ List<String> remainingArgs = <String>[];
+ for (int i = 0; i < count; i++) {
+ String arg = args[i];
+ if (arg == '--') {
+ while (i < count) {
+ remainingArgs.add(args[i++]);
+ }
+ } else if (arg.startsWith("-D")) {
+ definedVariables[arg.substring(2)] = args[++i];
+ } else {
+ remainingArgs.add(arg);
+ }
+ }
+ return remainingArgs;
+ }
List<String> _filterUnknowns(args) {
« no previous file with comments | « no previous file | pkg/analyzer/test/options_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698