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); |
} |