Index: pkg/args/lib/args.dart |
diff --git a/pkg/args/lib/args.dart b/pkg/args/lib/args.dart |
index 0cb81961a3ec2c1743f09a9138c389eb3e3013c1..52176ba6d8b1c2682fc7de5a0663dd5db5876eb4 100644 |
--- a/pkg/args/lib/args.dart |
+++ b/pkg/args/lib/args.dart |
@@ -77,18 +77,17 @@ |
* |
* var parser = new ArgParser(); |
* parser.addOption('mode'); |
- * parser.addFlag('verbose', defaultsTo: true); |
- * var results = parser.parse('['--mode', 'debug', 'something', 'else']); |
+ * parser.addFlag('verbose', abbr: 'v'); |
+ * var results = parser.parse('['--mode', 'debug', 'skip', '-v', 'me']); |
* |
* print(results['mode']); // debug |
* print(results['verbose']); // true |
* |
- * The [parse()] method will stop as soon as it reaches `--` or anything that |
- * it doesn't recognize as an option, flag, or option value. If there are still |
- * arguments left, they will be provided to you in |
+ * The [parse()] method will ignore any arguments it doesn't recognize and stop |
+ * if it reaches `--`. Any unhandled arguments will be provided to you in |
* [ArgResults.rest]. |
* |
- * print(results.rest); // ['something', 'else'] |
+ * print(results.rest); // ['skip', 'me'] |
* |
* ## Specifying options ## |
* |
@@ -179,7 +178,7 @@ |
* |
* [arm] ARM Holding 32-bit chip |
* [ia32] Intel x86 |
- * |
+ * |
* To assist the formatting of the usage help, single line help text will |
* be followed by a single new line. Options with multi-line help text |
* will be followed by two new lines. This provides spatial diversity between |
@@ -192,7 +191,6 @@ library args; |
import 'dart:math'; |
-// TODO(rnystrom): Use "package:" URL here when test.dart can handle pub. |
import 'src/utils.dart'; |
/** |
@@ -286,6 +284,7 @@ class ArgParser { |
_args = args; |
_current = 0; |
var results = {}; |
+ var rest = []; |
// Initialize flags to their defaults. |
_options.forEach((name, option) { |
@@ -312,8 +311,8 @@ class ArgParser { |
if (_parseAbbreviation(results)) continue; |
if (_parseLongOption(results)) continue; |
- // If we got here, the argument doesn't look like an option, so stop. |
- break; |
+ // If we got here, the argument doesn't look like an option, so ignore it. |
+ rest.add(arg); |
} |
// Set unspecified multivalued arguments to their default value, |
@@ -329,8 +328,9 @@ class ArgParser { |
} |
// Add in the leftover arguments we didn't parse. |
- return new ArgResults(results, |
- _args.getRange(_current, _args.length - _current)); |
+ rest.addAll(_args.getRange(_current, _args.length - _current)); |
+ |
+ return new ArgResults(results, rest); |
} |
/** |