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

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

Issue 383913003: Add .wasParsed() to ArgResults. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove "-dev". Created 6 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 | « pkg/args/lib/src/options.dart ('k') | pkg/args/pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/args/lib/src/parser.dart
diff --git a/pkg/args/lib/src/parser.dart b/pkg/args/lib/src/parser.dart
index 3f2e79dcec6937064b98a104ece9084c6e790df5..4d3417a12599df4b323b9e120f5501db597c65b1 100644
--- a/pkg/args/lib/src/parser.dart
+++ b/pkg/args/lib/src/parser.dart
@@ -4,7 +4,9 @@
library args.src.parser;
-import '../args.dart';
+import 'arg_parser.dart';
+import 'arg_results.dart';
+import 'option.dart';
final _SOLO_OPT = new RegExp(r'^-([a-zA-Z0-9])$');
final _ABBR_OPT = new RegExp(r'^-([a-zA-Z0-9]+)(.*)$');
@@ -46,15 +48,6 @@ class Parser {
ArgResults parse() {
var commandResults = null;
- // Initialize flags to their defaults.
- grammar.options.forEach((name, option) {
- if (option.allowMultiple) {
- results[name] = [];
- } else {
- results[name] = option.defaultValue;
- }
- });
-
// Parse the args.
while (args.length > 0) {
if (current == '--') {
@@ -89,21 +82,16 @@ class Parser {
rest.add(args.removeAt(0));
}
- // Set unspecified multivalued arguments to their default value,
- // if any, and invoke the callbacks.
+ // Invoke the callbacks.
grammar.options.forEach((name, option) {
- if (option.allowMultiple &&
- results[name].length == 0 &&
- option.defaultValue != null) {
- results[name].add(option.defaultValue);
- }
- if (option.callback != null) option.callback(results[name]);
+ if (option.callback == null) return;
+ option.callback(option.getOrDefault(results[name]));
});
// Add in the leftover arguments we didn't parse to the innermost command.
rest.addAll(args);
args.clear();
- return new ArgResults(results, commandName, commandResults, rest);
+ return newArgResults(grammar, results, commandName, commandResults, rest);
}
/// Pulls the value for [option] from the second argument in [args].
@@ -271,8 +259,9 @@ class Parser {
'"$value" is not an allowed value for option "${option.name}".');
}
- if (option.allowMultiple) {
- results[option.name].add(value);
+ if (option.isMultiple) {
+ var list = results.putIfAbsent(option.name, () => []);
+ list.add(value);
} else {
results[option.name] = value;
}
« no previous file with comments | « pkg/args/lib/src/options.dart ('k') | pkg/args/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698