Index: pkg/args/lib/args.dart |
diff --git a/pkg/args/lib/args.dart b/pkg/args/lib/args.dart |
index 304827b41ed4650f7d1b506c7f9a5240ac7d7ac0..48cef1642ece730acba2bbc42027c05a910255b0 100644 |
--- a/pkg/args/lib/args.dart |
+++ b/pkg/args/lib/args.dart |
@@ -285,11 +285,6 @@ class ArgParser { |
// Make sure the abbreviation isn't too long or in use. |
if (abbr != null) { |
- if (abbr.length > 1) { |
- throw new ArgumentError( |
- 'Abbreviation "$abbr" is longer than one character.'); |
- } |
- |
var existing = findByAbbreviation(abbr); |
if (existing != null) { |
throw new ArgumentError( |
@@ -342,7 +337,7 @@ class ArgParser { |
class Option { |
final String name; |
final String abbreviation; |
- final List allowed; |
+ final List<String> allowed; |
final defaultValue; |
final Function callback; |
final String help; |
@@ -353,7 +348,33 @@ class Option { |
Option(this.name, this.abbreviation, this.help, this.allowed, |
this.allowedHelp, this.defaultValue, this.callback, {this.isFlag, |
- this.negatable, this.allowMultiple: false}); |
+ this.negatable, this.allowMultiple: false}) { |
+ |
+ if (name.isEmpty) { |
kevmoo-old
2013/03/13 21:41:39
Removed the null check. And the test for null.
Gr
|
+ throw new ArgumentError('Name cannot be empty.'); |
+ } else if (name.startsWith('-')) { |
+ throw new ArgumentError('Name $name cannot start with "-".'); |
+ } |
+ |
+ // Ensure name does not contain any invalid characters. |
+ if (_invalidChars.hasMatch(name)) { |
+ throw new ArgumentError('Name "$name" contains invalid characters.'); |
+ } |
+ |
+ if (abbreviation != null) { |
+ if (abbreviation.length != 1) { |
+ throw new ArgumentError('Abbreviation must be null or have length 1.'); |
+ } else if(abbreviation == '-') { |
+ throw new ArgumentError('Abbreviation cannot be "-".'); |
+ } |
+ |
+ if (_invalidChars.hasMatch(abbreviation)) { |
+ throw new ArgumentError('Abbreviation is an invalid character.'); |
+ } |
+ } |
+ } |
+ |
+ static final _invalidChars = new RegExp(r'''[ \t\r\n"'\\/]'''); |
kevmoo-old
2013/03/13 21:41:39
*Totally* spaced on the static bit. No argument th
|
} |
/** |