| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** | 5 /** |
| 6 * This library lets you define parsers for parsing raw command-line arguments | 6 * This library lets you define parsers for parsing raw command-line arguments |
| 7 * into a set of options and values using [GNU][] and [POSIX][] style options. | 7 * into a set of options and values using [GNU][] and [POSIX][] style options. |
| 8 * | 8 * |
| 9 * ## Defining options ## | 9 * ## Defining options ## |
| 10 * | 10 * |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 #import('dart:math'); | 188 #import('dart:math'); |
| 189 | 189 |
| 190 // TODO(rnystrom): Use "package:" URL here when test.dart can handle pub. | 190 // TODO(rnystrom): Use "package:" URL here when test.dart can handle pub. |
| 191 #import('src/utils.dart'); | 191 #import('src/utils.dart'); |
| 192 | 192 |
| 193 /** | 193 /** |
| 194 * A class for taking a list of raw command line arguments and parsing out | 194 * A class for taking a list of raw command line arguments and parsing out |
| 195 * options and flags from them. | 195 * options and flags from them. |
| 196 */ | 196 */ |
| 197 class ArgParser { | 197 class ArgParser { |
| 198 static const _SOLO_OPT = const RegExp(@'^-([a-zA-Z0-9])$'); | 198 static const _SOLO_OPT = const RegExp(r'^-([a-zA-Z0-9])$'); |
| 199 static const _ABBR_OPT = const RegExp(@'^-([a-zA-Z0-9]+)(.*)$'); | 199 static const _ABBR_OPT = const RegExp(r'^-([a-zA-Z0-9]+)(.*)$'); |
| 200 static const _LONG_OPT = const RegExp(@'^--([a-zA-Z\-_0-9]+)(=(.*))?$'); | 200 static const _LONG_OPT = const RegExp(r'^--([a-zA-Z\-_0-9]+)(=(.*))?$'); |
| 201 | 201 |
| 202 final Map<String, _Option> _options; | 202 final Map<String, _Option> _options; |
| 203 | 203 |
| 204 /** | 204 /** |
| 205 * The names of the options, in the order that they were added. This way we | 205 * The names of the options, in the order that they were added. This way we |
| 206 * can generate usage information in the same order. | 206 * can generate usage information in the same order. |
| 207 */ | 207 */ |
| 208 // TODO(rnystrom): Use an ordered map type, if one appears. | 208 // TODO(rnystrom): Use an ordered map type, if one appears. |
| 209 final List<String> _optionNames; | 209 final List<String> _optionNames; |
| 210 | 210 |
| (...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 allowedBuffer.add(allowed); | 771 allowedBuffer.add(allowed); |
| 772 if (allowed == option.defaultValue) { | 772 if (allowed == option.defaultValue) { |
| 773 allowedBuffer.add(' (default)'); | 773 allowedBuffer.add(' (default)'); |
| 774 } | 774 } |
| 775 first = false; | 775 first = false; |
| 776 } | 776 } |
| 777 allowedBuffer.add(']'); | 777 allowedBuffer.add(']'); |
| 778 return allowedBuffer.toString(); | 778 return allowedBuffer.toString(); |
| 779 } | 779 } |
| 780 } | 780 } |
| OLD | NEW |