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

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

Issue 2989763002: Update charted to 0.4.8 and roll (Closed)
Patch Set: Removed Cutch from list of reviewers Created 3 years, 5 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
« no previous file with comments | « packages/args/lib/src/option.dart ('k') | packages/args/lib/src/usage.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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(",")) {
« no previous file with comments | « packages/args/lib/src/option.dart ('k') | packages/args/lib/src/usage.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698