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 * |
11 * To use this library, you create an [ArgParser] object which will contain | 11 * To use this library, you create an [ArgParser] object which will contain |
12 * the set of options you support: | 12 * the set of options you support: |
13 * | 13 * |
14 * var parser = new ArgParser(); | 14 * var parser = new ArgParser(); |
15 * | 15 * |
16 * Then you define a set of options on that parser using [addOption()] and | 16 * Then you define a set of options on that parser using [addOption()] and |
17 * [addFlag()]. The minimal way to create an option is: | 17 * [addFlag()]. The minimal way to create an option is: |
18 * | 18 * |
19 * parser.addOption('name'); | 19 * parser.addOption('name'); |
20 * | 20 * |
21 * This creates an option named "name". Options must be given a value on the | 21 * This creates an option named "name". Options must be given a value on the |
22 * command line. If you have a simple on/off flag, you can instead use: | 22 * command line. If you have a simple on/off flag, you can instead use: |
23 * | 23 * |
24 * parser.addFlag('name'); | 24 * parser.addFlag('name'); |
25 * | 25 * |
| 26 * Flag options will, by default, accept a 'no-' prefix to negate the option. |
| 27 * This can be disabled like so: |
| 28 * |
| 29 * parser.addFlag('name', negatable: false); |
| 30 * |
26 * (From here on out "option" will refer to both "regular" options and flags. | 31 * (From here on out "option" will refer to both "regular" options and flags. |
27 * In cases where the distinction matters, we'll use "non-flag option".) | 32 * In cases where the distinction matters, we'll use "non-flag option".) |
28 * | 33 * |
29 * Options may have an optional single-character abbreviation: | 34 * Options may have an optional single-character abbreviation: |
30 * | 35 * |
31 * parser.addOption('mode', abbr: 'm'); | 36 * parser.addOption('mode', abbr: 'm'); |
32 * parser.addFlag('verbose', abbr: 'v'); | 37 * parser.addFlag('verbose', abbr: 'v'); |
33 * | 38 * |
34 * They may also specify a default value. The default value will be used if the | 39 * They may also specify a default value. The default value will be used if the |
35 * option isn't provided: | 40 * option isn't provided: |
(...skipping 729 matching lines...) Loading... |
765 allowedBuffer.add(allowed); | 770 allowedBuffer.add(allowed); |
766 if (allowed == option.defaultValue) { | 771 if (allowed == option.defaultValue) { |
767 allowedBuffer.add(' (default)'); | 772 allowedBuffer.add(' (default)'); |
768 } | 773 } |
769 first = false; | 774 first = false; |
770 } | 775 } |
771 allowedBuffer.add(']'); | 776 allowedBuffer.add(']'); |
772 return allowedBuffer.toString(); | 777 return allowedBuffer.toString(); |
773 } | 778 } |
774 } | 779 } |
OLD | NEW |