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

Side by Side Diff: pkg/args/lib/src/options.dart

Issue 16802002: Moved the Option class to its own file in anticipation of working on it. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/args/lib/args.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 library options;
2
3 /**
4 * A command-line option. Includes both flags and options which take a value.
5 */
6 class Option {
7 final String name;
8 final String abbreviation;
9 final List<String> allowed;
10 final defaultValue;
11 final Function callback;
12 final String help;
13 final Map<String, String> allowedHelp;
14 final bool isFlag;
15 final bool negatable;
16 final bool allowMultiple;
17
18 Option(this.name, this.abbreviation, this.help, this.allowed,
19 this.allowedHelp, this.defaultValue, this.callback, {this.isFlag,
20 this.negatable, this.allowMultiple: false}) {
21
22 if (name.isEmpty) {
23 throw new ArgumentError('Name cannot be empty.');
24 } else if (name.startsWith('-')) {
25 throw new ArgumentError('Name $name cannot start with "-".');
26 }
27
28 // Ensure name does not contain any invalid characters.
29 if (_invalidChars.hasMatch(name)) {
30 throw new ArgumentError('Name "$name" contains invalid characters.');
31 }
32
33 if (abbreviation != null) {
34 if (abbreviation.length != 1) {
35 throw new ArgumentError('Abbreviation must be null or have length 1.');
36 } else if(abbreviation == '-') {
37 throw new ArgumentError('Abbreviation cannot be "-".');
38 }
39
40 if (_invalidChars.hasMatch(abbreviation)) {
41 throw new ArgumentError('Abbreviation is an invalid character.');
42 }
43 }
44 }
45
46 static final _invalidChars = new RegExp(r'''[ \t\r\n"'\\/]''');
47 }
OLDNEW
« no previous file with comments | « pkg/args/lib/args.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698