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

Unified Diff: lib/src/option.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
Index: lib/src/option.dart
diff --git a/lib/src/option.dart b/lib/src/option.dart
index 4045bce1e0b528b7d857631d75b1bbd38cdd49a8..07e87f68196b553490a7649ebd8a41c28b99274a 100644
--- a/lib/src/option.dart
+++ b/lib/src/option.dart
@@ -13,9 +13,10 @@ import 'dart:collection';
Option newOption(String name, String abbreviation, String help,
String valueHelp, List<String> allowed, Map<String, String> allowedHelp,
defaultValue, Function callback, OptionType type,
- {bool negatable, bool hide: false}) {
+ {bool negatable, bool splitCommas, bool hide: false}) {
return new Option._(name, abbreviation, help, valueHelp, allowed, allowedHelp,
- defaultValue, callback, type, negatable: negatable, hide: hide);
+ defaultValue, callback, type, negatable: negatable,
+ splitCommas: splitCommas, hide: hide);
}
/// A command-line option. Includes both flags and options which take a value.
@@ -30,6 +31,7 @@ class Option {
final Map<String, String> allowedHelp;
final OptionType type;
final bool negatable;
+ final bool splitCommas;
final bool hide;
/// Whether the option is boolean-valued flag.
@@ -43,13 +45,20 @@ class Option {
Option._(this.name, this.abbreviation, this.help, this.valueHelp,
List<String> allowed, Map<String, String> allowedHelp, this.defaultValue,
- this.callback, this.type, {this.negatable, this.hide: false})
+ this.callback, OptionType type, {this.negatable, bool splitCommas,
+ this.hide: false})
: this.allowed = allowed == null
? null
: new UnmodifiableListView(allowed),
this.allowedHelp = allowedHelp == null
? null
- : new UnmodifiableMapView(allowedHelp) {
+ : new UnmodifiableMapView(allowedHelp),
+ this.type = type,
+ // If the user doesn't specify [splitCommas], it defaults to true for
+ // multiple options.
+ this.splitCommas = splitCommas == null
+ ? type == OptionType.MULTIPLE
+ : splitCommas {
if (name.isEmpty) {
throw new ArgumentError('Name cannot be empty.');
} else if (name.startsWith('-')) {
« lib/src/arg_parser.dart ('K') | « lib/src/arg_parser.dart ('k') | lib/src/parser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698