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