| OLD | NEW |
| 1 library options; | 1 library options; |
| 2 | 2 |
| 3 import 'package:unmodifiable_collection/unmodifiable_collection.dart'; | 3 import 'package:unmodifiable_collection/unmodifiable_collection.dart'; |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * A command-line option. Includes both flags and options which take a value. | 6 * A command-line option. Includes both flags and options which take a value. |
| 7 */ | 7 */ |
| 8 class Option { | 8 class Option { |
| 9 final String name; | 9 final String name; |
| 10 final String abbreviation; | 10 final String abbreviation; |
| 11 final List<String> allowed; | 11 final List<String> allowed; |
| 12 final defaultValue; | 12 final defaultValue; |
| 13 final Function callback; | 13 final Function callback; |
| 14 final String help; | 14 final String help; |
| 15 final Map<String, String> allowedHelp; | 15 final Map<String, String> allowedHelp; |
| 16 final bool isFlag; | 16 final bool isFlag; |
| 17 final bool negatable; | 17 final bool negatable; |
| 18 final bool allowMultiple; | 18 final bool allowMultiple; |
| 19 final bool isHidden; |
| 19 | 20 |
| 20 Option(this.name, this.abbreviation, this.help, List<String> allowed, | 21 Option(this.name, this.abbreviation, this.help, List<String> allowed, |
| 21 Map<String, String> allowedHelp, this.defaultValue, this.callback, | 22 Map<String, String> allowedHelp, this.defaultValue, this.callback, |
| 22 {this.isFlag, this.negatable, this.allowMultiple: false}) : | 23 {this.isFlag, this.negatable, this.allowMultiple: false, |
| 24 this.isHidden: false}) : |
| 23 this.allowed = allowed == null ? | 25 this.allowed = allowed == null ? |
| 24 null : new UnmodifiableListView(allowed), | 26 null : new UnmodifiableListView(allowed), |
| 25 this.allowedHelp = allowedHelp == null ? | 27 this.allowedHelp = allowedHelp == null ? |
| 26 null : new UnmodifiableMapView(allowedHelp) { | 28 null : new UnmodifiableMapView(allowedHelp) { |
| 27 | 29 |
| 28 if (name.isEmpty) { | 30 if (name.isEmpty) { |
| 29 throw new ArgumentError('Name cannot be empty.'); | 31 throw new ArgumentError('Name cannot be empty.'); |
| 30 } else if (name.startsWith('-')) { | 32 } else if (name.startsWith('-')) { |
| 31 throw new ArgumentError('Name $name cannot start with "-".'); | 33 throw new ArgumentError('Name $name cannot start with "-".'); |
| 32 } | 34 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 44 } | 46 } |
| 45 | 47 |
| 46 if (_invalidChars.hasMatch(abbreviation)) { | 48 if (_invalidChars.hasMatch(abbreviation)) { |
| 47 throw new ArgumentError('Abbreviation is an invalid character.'); | 49 throw new ArgumentError('Abbreviation is an invalid character.'); |
| 48 } | 50 } |
| 49 } | 51 } |
| 50 } | 52 } |
| 51 | 53 |
| 52 static final _invalidChars = new RegExp(r'''[ \t\r\n"'\\/]'''); | 54 static final _invalidChars = new RegExp(r'''[ \t\r\n"'\\/]'''); |
| 53 } | 55 } |
| OLD | NEW |