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

Unified Diff: pkg/analyzer/lib/src/command_line/arguments.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/src/command_line/arguments_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/command_line/arguments.dart
diff --git a/pkg/analyzer/lib/src/command_line/arguments.dart b/pkg/analyzer/lib/src/command_line/arguments.dart
index 9b6e9f81f69d57a9fed1a88de6fd72d9f490739c..fdb57ebd75481e5546bed5aca5d39243dfd65a4c 100644
--- a/pkg/analyzer/lib/src/command_line/arguments.dart
+++ b/pkg/analyzer/lib/src/command_line/arguments.dart
@@ -165,6 +165,38 @@ void defineAnalysisArguments(ArgParser parser) {
}
/**
+ * Find arguments of the form -Dkey=value
+ * or argument pairs of the form -Dkey value
+ * and place those key/value pairs into [definedVariables].
+ * Return a list of arguments with the key/value arguments removed.
+ */
+List<String> extractDefinedVariables(
+ List<String> args, Map<String, String> definedVariables) {
+ //TODO(danrubel) extracting defined variables is already handled by the
+ // createContextBuilderOptions method.
+ // Long term we should switch to using that instead.
+ 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")) {
+ if (i + 1 < count) {
+ definedVariables[arg.substring(2)] = args[++i];
+ } else {
+ remainingArgs.add(arg);
+ }
+ } else {
+ remainingArgs.add(arg);
+ }
+ }
+ return remainingArgs;
+}
+
+/**
* Return a list of command-line arguments containing all of the given [args]
* that are defined by the given [parser]. An argument is considered to be
* defined by the parser if
« no previous file with comments | « no previous file | pkg/analyzer/test/src/command_line/arguments_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698