Take Iterables rather than Lists where possible (#83)
Take Iterables rather than Lists where possible
Closes #82
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c652630..1f38fad 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,11 @@
+## 1.1.0
+
+* `ArgParser.parse()` now takes an `Iterable<String>` rather than a
+ `List<String>`.
+
+* `ArgParser.addOption()`'s `allowed` option now takes an `Iterable<String>`
+ rather than a `List<String>`.
+
## 1.0.2
* Fix analyzer warning
diff --git a/lib/src/allow_anything_parser.dart b/lib/src/allow_anything_parser.dart
index 450920c..38daea5 100644
--- a/lib/src/allow_anything_parser.dart
+++ b/lib/src/allow_anything_parser.dart
@@ -34,7 +34,7 @@
{String abbr,
String help,
String valueHelp,
- List<String> allowed,
+ Iterable<String> allowed,
Map<String, String> allowedHelp,
String defaultsTo,
void callback(value),
@@ -50,7 +50,7 @@
"ArgParser.allowAnything().addSeparator() isn't supported.");
}
- ArgResults parse(List<String> args) =>
+ ArgResults parse(Iterable<String> args) =>
new Parser(null, this, args.toList()).parse();
String getUsage() => usage;
diff --git a/lib/src/arg_parser.dart b/lib/src/arg_parser.dart
index 62c8276..e91276d 100644
--- a/lib/src/arg_parser.dart
+++ b/lib/src/arg_parser.dart
@@ -111,7 +111,7 @@
{String abbr,
String help,
String valueHelp,
- List<String> allowed,
+ Iterable<String> allowed,
Map<String, String> allowedHelp,
String defaultsTo,
void callback(value),
@@ -133,7 +133,7 @@
String abbr,
String help,
String valueHelp,
- List<String> allowed,
+ Iterable<String> allowed,
Map<String, String> allowedHelp,
defaultsTo,
void callback(value),
@@ -172,7 +172,7 @@
/// Parses [args], a list of command-line arguments, matches them against the
/// flags and options defined by this parser, and returns the result.
- ArgResults parse(List<String> args) =>
+ ArgResults parse(Iterable<String> args) =>
new Parser(null, this, args.toList()).parse();
/// Generates a string displaying usage information for the defined options.
diff --git a/lib/src/option.dart b/lib/src/option.dart
index 3ff7fe8..55cc566 100644
--- a/lib/src/option.dart
+++ b/lib/src/option.dart
@@ -2,8 +2,6 @@
// 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.
-import 'dart:collection';
-
/// Creates a new [Option].
///
/// Since [Option] doesn't have a public constructor, this lets `ArgParser`
@@ -13,7 +11,7 @@
String abbreviation,
String help,
String valueHelp,
- List<String> allowed,
+ Iterable<String> allowed,
Map<String, String> allowedHelp,
defaultValue,
Function callback,
@@ -55,7 +53,7 @@
this.abbreviation,
this.help,
this.valueHelp,
- List<String> allowed,
+ Iterable<String> allowed,
Map<String, String> allowedHelp,
this.defaultValue,
this.callback,
@@ -63,10 +61,9 @@
{this.negatable,
bool splitCommas,
this.hide: false})
- : this.allowed =
- allowed == null ? null : new UnmodifiableListView(allowed),
+ : this.allowed = allowed == null ? null : new List.unmodifiable(allowed),
this.allowedHelp =
- allowedHelp == null ? null : new UnmodifiableMapView(allowedHelp),
+ allowedHelp == null ? null : new Map.unmodifiable(allowedHelp),
this.type = type,
// If the user doesn't specify [splitCommas], it defaults to true for
// multiple options.
diff --git a/pubspec.yaml b/pubspec.yaml
index 4692428..4e3311c 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: args
-version: 1.0.2
+version: 1.1.0
author: "Dart Team <misc@dartlang.org>"
homepage: https://github.com/dart-lang/args
description: >