OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library args.src.arg_results; | 5 library args.src.arg_results; |
6 | 6 |
7 import 'package:collection/wrappers.dart'; | 7 import 'package:collection/wrappers.dart'; |
8 | 8 |
9 import 'arg_parser.dart'; | 9 import 'arg_parser.dart'; |
10 | 10 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 } | 63 } |
64 | 64 |
65 return _parser.options[name].getOrDefault(_parsed[name]); | 65 return _parser.options[name].getOrDefault(_parsed[name]); |
66 } | 66 } |
67 | 67 |
68 /// Get the names of the available options as an [Iterable]. | 68 /// Get the names of the available options as an [Iterable]. |
69 /// | 69 /// |
70 /// This includes the options whose values were parsed or that have defaults. | 70 /// This includes the options whose values were parsed or that have defaults. |
71 /// Options that weren't present and have no default will be omitted. | 71 /// Options that weren't present and have no default will be omitted. |
72 Iterable<String> get options { | 72 Iterable<String> get options { |
73 var result = new Set.from(_parsed.keys); | 73 var result = new Set<String>.from(_parsed.keys); |
74 | 74 |
75 // Include the options that have defaults. | 75 // Include the options that have defaults. |
76 _parser.options.forEach((name, option) { | 76 _parser.options.forEach((name, option) { |
77 if (option.defaultValue != null) result.add(name); | 77 if (option.defaultValue != null) result.add(name); |
78 }); | 78 }); |
79 | 79 |
80 return result; | 80 return result; |
81 } | 81 } |
82 | 82 |
83 /// Returns `true` if the option with [name] was parsed from an actual | 83 /// Returns `true` if the option with [name] was parsed from an actual |
84 /// argument. | 84 /// argument. |
85 /// | 85 /// |
86 /// Returns `false` if it wasn't provided and the default value or no default | 86 /// Returns `false` if it wasn't provided and the default value or no default |
87 /// value would be used instead. | 87 /// value would be used instead. |
88 bool wasParsed(String name) { | 88 bool wasParsed(String name) { |
89 var option = _parser.options[name]; | 89 var option = _parser.options[name]; |
90 if (option == null) { | 90 if (option == null) { |
91 throw new ArgumentError('Could not find an option named "$name".'); | 91 throw new ArgumentError('Could not find an option named "$name".'); |
92 } | 92 } |
93 | 93 |
94 return _parsed.containsKey(name); | 94 return _parsed.containsKey(name); |
95 } | 95 } |
96 } | 96 } |
OLD | NEW |