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

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

Issue 383913003: Add .wasParsed() to ArgResults. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove "-dev". Created 6 years, 5 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/src/option.dart ('k') | pkg/args/lib/src/parser.dart » ('j') | 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 import 'package:collection/wrappers.dart';
4
5 /// A command-line option. Includes both flags and options which take a value.
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 String valueHelp;
14 final Map<String, String> allowedHelp;
15 final bool isFlag;
16 final bool negatable;
17 final bool allowMultiple;
18 final bool hide;
19
20 Option(this.name, this.abbreviation, this.help, this.valueHelp,
21 List<String> allowed, Map<String, String> allowedHelp, this.defaultValue,
22 this.callback, {this.isFlag, this.negatable, this.allowMultiple: false,
23 this.hide: false}) :
24 this.allowed = allowed == null ?
25 null : new UnmodifiableListView(allowed),
26 this.allowedHelp = allowedHelp == null ?
27 null : new UnmodifiableMapView(allowedHelp) {
28
29 if (name.isEmpty) {
30 throw new ArgumentError('Name cannot be empty.');
31 } else if (name.startsWith('-')) {
32 throw new ArgumentError('Name $name cannot start with "-".');
33 }
34
35 // Ensure name does not contain any invalid characters.
36 if (_invalidChars.hasMatch(name)) {
37 throw new ArgumentError('Name "$name" contains invalid characters.');
38 }
39
40 if (abbreviation != null) {
41 if (abbreviation.length != 1) {
42 throw new ArgumentError('Abbreviation must be null or have length 1.');
43 } else if(abbreviation == '-') {
44 throw new ArgumentError('Abbreviation cannot be "-".');
45 }
46
47 if (_invalidChars.hasMatch(abbreviation)) {
48 throw new ArgumentError('Abbreviation is an invalid character.');
49 }
50 }
51 }
52
53 static final _invalidChars = new RegExp(r'''[ \t\r\n"'\\/]''');
54 }
OLDNEW
« no previous file with comments | « pkg/args/lib/src/option.dart ('k') | pkg/args/lib/src/parser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698