| Index: packages/args/lib/src/parser.dart
|
| diff --git a/packages/args/lib/src/parser.dart b/packages/args/lib/src/parser.dart
|
| index a10692d4ed84e328122ecefce672089a48dede34..64374fcb1a1677aa488ebe418d9668b5fc6ad947 100644
|
| --- a/packages/args/lib/src/parser.dart
|
| +++ b/packages/args/lib/src/parser.dart
|
| @@ -2,9 +2,8 @@
|
| // for details. All rights reserved. Use of this source code is governed by a
|
| // BSD-style license that can be found in the LICENSE file.
|
|
|
| -library args.src.parser;
|
| -
|
| import 'arg_parser.dart';
|
| +import 'arg_parser_exception.dart';
|
| import 'arg_results.dart';
|
| import 'option.dart';
|
|
|
| @@ -37,7 +36,8 @@ class Parser {
|
| /// The accumulated parsed options.
|
| final Map<String, dynamic> results = <String, dynamic>{};
|
|
|
| - Parser(this.commandName, this.grammar, this.args, this.parent, rest) {
|
| + Parser(this.commandName, this.grammar, this.args,
|
| + [this.parent, List<String> rest]) {
|
| if (rest != null) this.rest.addAll(rest);
|
| }
|
|
|
| @@ -64,7 +64,15 @@ class Parser {
|
| validate(rest.isEmpty, 'Cannot specify arguments before a command.');
|
| var commandName = args.removeAt(0);
|
| var commandParser = new Parser(commandName, command, args, this, rest);
|
| - commandResults = commandParser.parse();
|
| +
|
| + try {
|
| + commandResults = commandParser.parse();
|
| + } on ArgParserException catch (error) {
|
| + if (commandName == null) rethrow;
|
| + throw new ArgParserException(
|
| + error.message,
|
| + [commandName]..addAll(error.commands));
|
| + }
|
|
|
| // All remaining arguments were passed to command so clear them here.
|
| rest.clear();
|
| @@ -243,9 +251,9 @@ class Parser {
|
|
|
| /// Called during parsing to validate the arguments.
|
| ///
|
| - /// Throws a [FormatException] if [condition] is `false`.
|
| + /// Throws an [ArgParserException] if [condition] is `false`.
|
| void validate(bool condition, String message) {
|
| - if (!condition) throw new FormatException(message);
|
| + if (!condition) throw new ArgParserException(message);
|
| }
|
|
|
| /// Validates and stores [value] as the value for [option], which must not be
|
| @@ -259,7 +267,7 @@ class Parser {
|
| return;
|
| }
|
|
|
| - var list = results.putIfAbsent(option.name, () => []);
|
| + var list = results.putIfAbsent(option.name, () => <String>[]);
|
|
|
| if (option.splitCommas) {
|
| for (var element in value.split(",")) {
|
|
|