| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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.parser; | 5 library args.src.parser; |
| 6 | 6 |
| 7 import 'arg_parser.dart'; | 7 import 'arg_parser.dart'; |
| 8 import 'arg_results.dart'; | 8 import 'arg_results.dart'; |
| 9 import 'option.dart'; | 9 import 'option.dart'; |
| 10 | 10 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 grammar, results, commandName, commandResults, rest, arguments); | 96 grammar, results, commandName, commandResults, rest, arguments); |
| 97 } | 97 } |
| 98 | 98 |
| 99 /// Pulls the value for [option] from the second argument in [args]. | 99 /// Pulls the value for [option] from the second argument in [args]. |
| 100 /// | 100 /// |
| 101 /// Validates that there is a valid value there. | 101 /// Validates that there is a valid value there. |
| 102 void readNextArgAsValue(Option option) { | 102 void readNextArgAsValue(Option option) { |
| 103 // Take the option argument from the next command line arg. | 103 // Take the option argument from the next command line arg. |
| 104 validate(args.length > 0, 'Missing argument for "${option.name}".'); | 104 validate(args.length > 0, 'Missing argument for "${option.name}".'); |
| 105 | 105 |
| 106 // Make sure it isn't an option itself. | |
| 107 validate(!_ABBR_OPT.hasMatch(current) && !_LONG_OPT.hasMatch(current), | |
| 108 'Missing argument for "${option.name}".'); | |
| 109 | |
| 110 setOption(results, option, current); | 106 setOption(results, option, current); |
| 111 args.removeAt(0); | 107 args.removeAt(0); |
| 112 } | 108 } |
| 113 | 109 |
| 114 /// Tries to parse the current argument as a "solo" option, which is a single | 110 /// Tries to parse the current argument as a "solo" option, which is a single |
| 115 /// hyphen followed by a single letter. | 111 /// hyphen followed by a single letter. |
| 116 /// | 112 /// |
| 117 /// We treat this differently than collapsed abbreviations (like "-abc") to | 113 /// We treat this differently than collapsed abbreviations (like "-abc") to |
| 118 /// handle the possible value that may follow it. | 114 /// handle the possible value that may follow it. |
| 119 bool parseSoloOption() { | 115 bool parseSoloOption() { |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 } | 280 } |
| 285 | 281 |
| 286 /// Validates that [value] is allowed as a value of [option]. | 282 /// Validates that [value] is allowed as a value of [option]. |
| 287 void _validateAllowed(Option option, String value) { | 283 void _validateAllowed(Option option, String value) { |
| 288 if (option.allowed == null) return; | 284 if (option.allowed == null) return; |
| 289 | 285 |
| 290 validate(option.allowed.contains(value), | 286 validate(option.allowed.contains(value), |
| 291 '"$value" is not an allowed value for option "${option.name}".'); | 287 '"$value" is not an allowed value for option "${option.name}".'); |
| 292 } | 288 } |
| 293 } | 289 } |
| OLD | NEW |