| 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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 */ | 180 */ |
| 181 #library('args'); | 181 #library('args'); |
| 182 | 182 |
| 183 #import('utils.dart'); | 183 #import('utils.dart'); |
| 184 | 184 |
| 185 /** | 185 /** |
| 186 * A class for taking a list of raw command line arguments and parsing out | 186 * A class for taking a list of raw command line arguments and parsing out |
| 187 * options and flags from them. | 187 * options and flags from them. |
| 188 */ | 188 */ |
| 189 class ArgParser { | 189 class ArgParser { |
| 190 static final _SOLO_OPT = const RegExp(@'^-([a-z0-9])$'); | 190 static final _SOLO_OPT = const RegExp(@'^-([a-zA-Z0-9])$'); |
| 191 static final _ABBR_OPT = const RegExp(@'^-([a-z0-9]+)(.*)$'); | 191 static final _ABBR_OPT = const RegExp(@'^-([a-zA-Z0-9]+)(.*)$'); |
| 192 static final _LONG_OPT = const RegExp(@'^--([a-z\-_0-9]+)(=(.*))?$'); | 192 static final _LONG_OPT = const RegExp(@'^--([a-zA-Z\-_0-9]+)(=(.*))?$'); |
| 193 | 193 |
| 194 final Map<String, _Option> _options; | 194 final Map<String, _Option> _options; |
| 195 | 195 |
| 196 /** | 196 /** |
| 197 * The names of the options, in the order that they were added. This way we | 197 * The names of the options, in the order that they were added. This way we |
| 198 * can generate usage information in the same order. | 198 * can generate usage information in the same order. |
| 199 */ | 199 */ |
| 200 // TODO(rnystrom): Use an ordered map type, if one appears. | 200 // TODO(rnystrom): Use an ordered map type, if one appears. |
| 201 final List<String> _optionNames; | 201 final List<String> _optionNames; |
| 202 | 202 |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 allowedBuffer.add(allowed); | 749 allowedBuffer.add(allowed); |
| 750 if (allowed == option.defaultValue) { | 750 if (allowed == option.defaultValue) { |
| 751 allowedBuffer.add(' (default)'); | 751 allowedBuffer.add(' (default)'); |
| 752 } | 752 } |
| 753 first = false; | 753 first = false; |
| 754 } | 754 } |
| 755 allowedBuffer.add(']'); | 755 allowedBuffer.add(']'); |
| 756 return allowedBuffer.toString(); | 756 return allowedBuffer.toString(); |
| 757 } | 757 } |
| 758 } | 758 } |
| OLD | NEW |