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

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: Add a splitCommas option. 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
Index: lib/src/arg_parser.dart
diff --git a/lib/src/arg_parser.dart b/lib/src/arg_parser.dart
index e7f728c034954593318d4ace2bd5be745b38f6ba..9c0a841576d5c4026f766aad533816b51c4c0915 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 '
Bob Nystrom 2015/03/04 22:01:37 If you wrap before the string literal, you don't h
nweiz 2015/03/04 22:05:41 Done.
+ 'false.');
+ }
+
_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

Powered by Google App Engine
This is Rietveld 408576698