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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 | 182 |
183 #import('dart:math'); | 183 #import('dart:math'); |
184 | 184 |
185 #import('utils.dart'); | 185 #import('utils.dart'); |
186 | 186 |
187 /** | 187 /** |
188 * A class for taking a list of raw command line arguments and parsing out | 188 * A class for taking a list of raw command line arguments and parsing out |
189 * options and flags from them. | 189 * options and flags from them. |
190 */ | 190 */ |
191 class ArgParser { | 191 class ArgParser { |
192 static final _SOLO_OPT = const RegExp(@'^-([a-zA-Z0-9])$'); | 192 static const _SOLO_OPT = const RegExp(@'^-([a-zA-Z0-9])$'); |
193 static final _ABBR_OPT = const RegExp(@'^-([a-zA-Z0-9]+)(.*)$'); | 193 static const _ABBR_OPT = const RegExp(@'^-([a-zA-Z0-9]+)(.*)$'); |
194 static final _LONG_OPT = const RegExp(@'^--([a-zA-Z\-_0-9]+)(=(.*))?$'); | 194 static const _LONG_OPT = const RegExp(@'^--([a-zA-Z\-_0-9]+)(=(.*))?$'); |
195 | 195 |
196 final Map<String, _Option> _options; | 196 final Map<String, _Option> _options; |
197 | 197 |
198 /** | 198 /** |
199 * The names of the options, in the order that they were added. This way we | 199 * The names of the options, in the order that they were added. This way we |
200 * can generate usage information in the same order. | 200 * can generate usage information in the same order. |
201 */ | 201 */ |
202 // TODO(rnystrom): Use an ordered map type, if one appears. | 202 // TODO(rnystrom): Use an ordered map type, if one appears. |
203 final List<String> _optionNames; | 203 final List<String> _optionNames; |
204 | 204 |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 * defined options. Internally, it works like a tabular printer. The output is | 558 * defined options. Internally, it works like a tabular printer. The output is |
559 * divided into three horizontal columns, like so: | 559 * divided into three horizontal columns, like so: |
560 * | 560 * |
561 * -h, --help Prints the usage information | 561 * -h, --help Prints the usage information |
562 * | | | | | 562 * | | | | |
563 * | 563 * |
564 * It builds the usage text up one column at a time and handles padding with | 564 * It builds the usage text up one column at a time and handles padding with |
565 * spaces and wrapping to the next line to keep the cells correctly lined up. | 565 * spaces and wrapping to the next line to keep the cells correctly lined up. |
566 */ | 566 */ |
567 class _Usage { | 567 class _Usage { |
568 static final NUM_COLUMNS = 3; // Abbreviation, long name, help. | 568 static const NUM_COLUMNS = 3; // Abbreviation, long name, help. |
569 | 569 |
570 /** The parser this is generating usage for. */ | 570 /** The parser this is generating usage for. */ |
571 final ArgParser args; | 571 final ArgParser args; |
572 | 572 |
573 /** The working buffer for the generated usage text. */ | 573 /** The working buffer for the generated usage text. */ |
574 StringBuffer buffer; | 574 StringBuffer buffer; |
575 | 575 |
576 /** | 576 /** |
577 * The column that the "cursor" is currently on. If the next call to | 577 * The column that the "cursor" is currently on. If the next call to |
578 * [write()] is not for this column, it will correctly handle advancing to | 578 * [write()] is not for this column, it will correctly handle advancing to |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 allowedBuffer.add(allowed); | 765 allowedBuffer.add(allowed); |
766 if (allowed == option.defaultValue) { | 766 if (allowed == option.defaultValue) { |
767 allowedBuffer.add(' (default)'); | 767 allowedBuffer.add(' (default)'); |
768 } | 768 } |
769 first = false; | 769 first = false; |
770 } | 770 } |
771 allowedBuffer.add(']'); | 771 allowedBuffer.add(']'); |
772 return allowedBuffer.toString(); | 772 return allowedBuffer.toString(); |
773 } | 773 } |
774 } | 774 } |
OLD | NEW |