| 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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 * --arch The architecture to compile for | 173 * --arch The architecture to compile for |
| 174 * | 174 * |
| 175 * [arm] ARM Holding 32-bit chip | 175 * [arm] ARM Holding 32-bit chip |
| 176 * [ia32] Intel x86 | 176 * [ia32] Intel x86 |
| 177 * | 177 * |
| 178 * [posix]: http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap12.h
tml#tag_12_02 | 178 * [posix]: http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap12.h
tml#tag_12_02 |
| 179 * [gnu]: http://www.gnu.org/prep/standards/standards.html#Command_002dLine-Inte
rfaces | 179 * [gnu]: http://www.gnu.org/prep/standards/standards.html#Command_002dLine-Inte
rfaces |
| 180 */ | 180 */ |
| 181 #library('args'); | 181 #library('args'); |
| 182 | 182 |
| 183 #import('dart:math'); |
| 184 |
| 183 #import('utils.dart'); | 185 #import('utils.dart'); |
| 184 | 186 |
| 185 /** | 187 /** |
| 186 * 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 |
| 187 * options and flags from them. | 189 * options and flags from them. |
| 188 */ | 190 */ |
| 189 class ArgParser { | 191 class ArgParser { |
| 190 static final _SOLO_OPT = const RegExp(@'^-([a-zA-Z0-9])$'); | 192 static final _SOLO_OPT = const RegExp(@'^-([a-zA-Z0-9])$'); |
| 191 static final _ABBR_OPT = const RegExp(@'^-([a-zA-Z0-9]+)(.*)$'); | 193 static final _ABBR_OPT = const RegExp(@'^-([a-zA-Z0-9]+)(.*)$'); |
| 192 static final _LONG_OPT = const RegExp(@'^--([a-zA-Z\-_0-9]+)(=(.*))?$'); | 194 static final _LONG_OPT = const RegExp(@'^--([a-zA-Z\-_0-9]+)(=(.*))?$'); |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 return ' [$allowed]'; | 667 return ' [$allowed]'; |
| 666 } | 668 } |
| 667 | 669 |
| 668 void calculateColumnWidths() { | 670 void calculateColumnWidths() { |
| 669 int abbr = 0; | 671 int abbr = 0; |
| 670 int title = 0; | 672 int title = 0; |
| 671 for (var name in args._optionNames) { | 673 for (var name in args._optionNames) { |
| 672 var option = args._options[name]; | 674 var option = args._options[name]; |
| 673 | 675 |
| 674 // Make room in the first column if there are abbreviations. | 676 // Make room in the first column if there are abbreviations. |
| 675 abbr = Math.max(abbr, getAbbreviation(option).length); | 677 abbr = max(abbr, getAbbreviation(option).length); |
| 676 | 678 |
| 677 // Make room for the option. | 679 // Make room for the option. |
| 678 title = Math.max(title, getLongOption(option).length); | 680 title = max(title, getLongOption(option).length); |
| 679 | 681 |
| 680 // Make room for the allowed help. | 682 // Make room for the allowed help. |
| 681 if (option.allowedHelp != null) { | 683 if (option.allowedHelp != null) { |
| 682 for (var allowed in option.allowedHelp.getKeys()) { | 684 for (var allowed in option.allowedHelp.getKeys()) { |
| 683 title = Math.max(title, getAllowedTitle(allowed).length); | 685 title = max(title, getAllowedTitle(allowed).length); |
| 684 } | 686 } |
| 685 } | 687 } |
| 686 } | 688 } |
| 687 | 689 |
| 688 // Leave a gutter between the columns. | 690 // Leave a gutter between the columns. |
| 689 title += 4; | 691 title += 4; |
| 690 columnWidths = [abbr, title]; | 692 columnWidths = [abbr, title]; |
| 691 } | 693 } |
| 692 | 694 |
| 693 newline() { | 695 newline() { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 allowedBuffer.add(allowed); | 765 allowedBuffer.add(allowed); |
| 764 if (allowed == option.defaultValue) { | 766 if (allowed == option.defaultValue) { |
| 765 allowedBuffer.add(' (default)'); | 767 allowedBuffer.add(' (default)'); |
| 766 } | 768 } |
| 767 first = false; | 769 first = false; |
| 768 } | 770 } |
| 769 allowedBuffer.add(']'); | 771 allowedBuffer.add(']'); |
| 770 return allowedBuffer.toString(); | 772 return allowedBuffer.toString(); |
| 771 } | 773 } |
| 772 } | 774 } |
| OLD | NEW |