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

Unified Diff: lib/src/arg_parser.dart

Issue 975463004: Parse comma-separated multiple values. (Closed) Base URL: git@github.com:dart-lang/args@master
Patch Set: Code review changes Created 5 years, 10 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 | « README.md ('k') | lib/src/option.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/arg_parser.dart
diff --git a/lib/src/arg_parser.dart b/lib/src/arg_parser.dart
index e7f728c034954593318d4ace2bd5be745b38f6ba..49d6aa6bbf6dc4d7a965536049fd8c305e87006e 100644
--- a/lib/src/arg_parser.dart
+++ b/lib/src/arg_parser.dart
@@ -77,18 +77,25 @@ class ArgParser {
///
/// * There is already an option with name [name].
/// * There is already an option using abbreviation [abbr].
+ /// * [splitCommas] is passed but [allowMultiple] is `false`.
void addOption(String name, {String abbr, String help, String valueHelp,
List<String> allowed, Map<String, String> allowedHelp, String defaultsTo,
- void callback(value), bool allowMultiple: false, bool hide: false}) {
+ void callback(value), bool allowMultiple: false, bool splitCommas,
+ bool hide: false}) {
+ if (!allowMultiple && splitCommas != null) {
+ throw new ArgumentError(
+ 'splitCommas may not be set if allowMultiple is false.');
Sean Eagan 2015/03/04 22:28:03 Why not? Seems like it would be reasonable that s
nweiz 2015/03/04 22:39:55 Why would you want to forbid the latter? That prov
+ }
+
_addOption(name, abbr, help, valueHelp, allowed, allowedHelp, defaultsTo,
callback, allowMultiple ? OptionType.MULTIPLE : OptionType.SINGLE,
- hide: hide);
+ splitCommas: splitCommas, hide: hide);
}
void _addOption(String name, String abbr, String help, String valueHelp,
List<String> allowed, Map<String, String> allowedHelp, defaultsTo,
void callback(value), OptionType type,
- {bool negatable: false, bool hide: false}) {
+ {bool negatable: false, bool splitCommas, bool hide: false}) {
// Make sure the name isn't in use.
if (_options.containsKey(name)) {
throw new ArgumentError('Duplicate option "$name".');
@@ -105,7 +112,7 @@ class ArgParser {
_options[name] = newOption(name, abbr, help, valueHelp, allowed,
allowedHelp, defaultsTo, callback, type,
- negatable: negatable, hide: hide);
+ negatable: negatable, splitCommas: splitCommas, hide: hide);
}
/// Parses [args], a list of command-line arguments, matches them against the
« no previous file with comments | « README.md ('k') | lib/src/option.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698