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

Unified Diff: pkg/args/lib/src/parser.dart

Issue 12545013: Added the continueParsing option to ArgParser. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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
Index: pkg/args/lib/src/parser.dart
diff --git a/pkg/args/lib/src/parser.dart b/pkg/args/lib/src/parser.dart
index d35f9ea4aff1bb67a1c20034b17574168d0c6502..23a9d488f440b1efba0ea3ddd24072824e6b189d 100644
--- a/pkg/args/lib/src/parser.dart
+++ b/pkg/args/lib/src/parser.dart
@@ -42,9 +42,16 @@ class Parser {
/** The current argument being parsed. */
String get current => args[0];
- /** Parses the arguments. This can only be called once. */
- ArgResults parse() {
+ /**
+ * Parses the arguments. This can only be called once.
+ *
+ * If [continueParsing] is set, the parser will continue parsing even after it
+ * finds an argument that is not an option. This allows you to specify options
+ * after your command parameters.
+ */
+ ArgResults parse({continueParsing: false}) {
var commandResults = null;
+ var rest = [];
// Initialize flags to their defaults.
grammar.options.forEach((name, option) {
@@ -79,8 +86,12 @@ class Parser {
if (parseAbbreviation(this)) continue;
if (parseLongOption()) continue;
- // If we got here, the argument doesn't look like an option, so stop.
- break;
+ if (!continueParsing) {
+ // If we got here, the argument doesn't look like an option, so stop.
+ break;
+ } else {
+ rest.add(args.removeAt(0));
+ }
}
// Set unspecified multivalued arguments to their default value,
@@ -95,7 +106,7 @@ class Parser {
});
// Add in the leftover arguments we didn't parse to the innermost command.
- var rest = args.toList();
+ rest.addAll(args.toList());
args.clear();
return new ArgResults(results, commandName, commandResults, rest);
}

Powered by Google App Engine
This is Rietveld 408576698