OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 * ## Installing ## | 9 * ## Installing ## |
10 * | 10 * |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
340 } | 340 } |
341 | 341 |
342 options[name] = new Option(name, abbr, help, allowed, allowedHelp, | 342 options[name] = new Option(name, abbr, help, allowed, allowedHelp, |
343 defaultsTo, callback, isFlag: isFlag, negatable: negatable, | 343 defaultsTo, callback, isFlag: isFlag, negatable: negatable, |
344 allowMultiple: allowMultiple); | 344 allowMultiple: allowMultiple); |
345 } | 345 } |
346 | 346 |
347 /** | 347 /** |
348 * Parses [args], a list of command-line arguments, matches them against the | 348 * Parses [args], a list of command-line arguments, matches them against the |
349 * flags and options defined by this parser, and returns the result. | 349 * flags and options defined by this parser, and returns the result. |
350 * | |
351 * If [allowTrailingOptions] is set, the parser will continue parsing even | |
352 * after it finds an argument that is neither an option nor a command. | |
353 * This allows options to be specified after command parameters. | |
Bob Nystrom
2013/06/24 15:53:20
"command parameters" -> "regular arguments".
Andrei Mouravski
2013/06/24 20:41:04
Done.
| |
354 * | |
355 * [allowTrailingOptions] is false by default, so when a non-option, | |
356 * non-command argument is encountered, it and all remaining arguments, | |
357 * even those that look like options are passed to the leafmost command. | |
Bob Nystrom
2013/06/24 15:53:20
"leafmost" -> "innermost".
Andrei Mouravski
2013/06/24 20:41:04
Done.
| |
358 * | |
359 * An argument that looks like an option, but does not match any option will | |
360 * throw a [FormatException], regardless of the value | |
361 * of [allowTrailingOptions]. | |
Bob Nystrom
2013/06/24 15:53:20
This is a bit confusing. It isn't clear that this
Andrei Mouravski
2013/06/24 20:41:04
Done.
| |
350 */ | 362 */ |
351 ArgResults parse(List<String> args) => | 363 ArgResults parse(List<String> args, {bool allowTrailingOptions}) { |
352 new Parser(null, this, args.toList()).parse(); | 364 if (allowTrailingOptions == null) allowTrailingOptions = false; |
365 return new Parser(null, this, args.toList(), allowTrailingOptions).parse(); | |
Bob Nystrom
2013/06/24 15:53:20
It should be a named argument here too.
Andrei Mouravski
2013/06/24 20:41:04
Done.
| |
366 } | |
353 | 367 |
354 /** | 368 /** |
355 * Generates a string displaying usage information for the defined options. | 369 * Generates a string displaying usage information for the defined options. |
356 * This is basically the help text shown on the command line. | 370 * This is basically the help text shown on the command line. |
357 */ | 371 */ |
358 String getUsage() => new Usage(this).generate(); | 372 String getUsage() => new Usage(this).generate(); |
359 | 373 |
360 /** | 374 /** |
361 * Get the default value for an option. Useful after parsing to test | 375 * Get the default value for an option. Useful after parsing to test |
362 * if the user specified something other than the default. | 376 * if the user specified something other than the default. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
415 'Could not find an option named "$name".'); | 429 'Could not find an option named "$name".'); |
416 } | 430 } |
417 | 431 |
418 return _options[name]; | 432 return _options[name]; |
419 } | 433 } |
420 | 434 |
421 /** Get the names of the options as an [Iterable]. */ | 435 /** Get the names of the options as an [Iterable]. */ |
422 Iterable<String> get options => _options.keys; | 436 Iterable<String> get options => _options.keys; |
423 } | 437 } |
424 | 438 |
OLD | NEW |