Chromium Code Reviews| 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 * Parser support for transforming raw command-line arguments into a set | 6 * Parser support for transforming raw command-line arguments into a set |
| 7 * of options and values. | 7 * of options and values. |
| 8 * | 8 * |
| 9 * This library supports [GNU][] and [POSIX][] style options, and it works | 9 * This library supports [GNU][] and [POSIX][] style options, and it works |
| 10 * in both server-side and client-side apps. | 10 * in both server-side and client-side apps. |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 327 } | 327 } |
| 328 | 328 |
| 329 /** | 329 /** |
| 330 * Defines a value-taking option. Throws an [ArgumentError] if: | 330 * Defines a value-taking option. Throws an [ArgumentError] if: |
| 331 * | 331 * |
| 332 * * There is already an option with name [name]. | 332 * * There is already an option with name [name]. |
| 333 * * There is already an option using abbreviation [abbr]. | 333 * * There is already an option using abbreviation [abbr]. |
| 334 */ | 334 */ |
| 335 void addOption(String name, {String abbr, String help, List<String> allowed, | 335 void addOption(String name, {String abbr, String help, List<String> allowed, |
| 336 Map<String, String> allowedHelp, String defaultsTo, | 336 Map<String, String> allowedHelp, String defaultsTo, |
| 337 void callback(value), bool allowMultiple: false}) { | 337 void callback(value), bool allowMultiple: false, |
| 338 bool isHidden: false}) { | |
|
Bob Nystrom
2013/09/24 20:57:07
Let's do "hide" for the named parameter.
nweiz
2013/09/24 21:01:17
Done.
| |
| 338 _addOption(name, abbr, help, allowed, allowedHelp, defaultsTo, | 339 _addOption(name, abbr, help, allowed, allowedHelp, defaultsTo, |
| 339 callback, isFlag: false, allowMultiple: allowMultiple); | 340 callback, isFlag: false, allowMultiple: allowMultiple, |
| 341 isHidden: isHidden); | |
| 340 } | 342 } |
| 341 | 343 |
| 342 void _addOption(String name, String abbr, String help, List<String> allowed, | 344 void _addOption(String name, String abbr, String help, List<String> allowed, |
| 343 Map<String, String> allowedHelp, defaultsTo, | 345 Map<String, String> allowedHelp, defaultsTo, |
| 344 void callback(value), {bool isFlag, bool negatable: false, | 346 void callback(value), {bool isFlag, bool negatable: false, |
| 345 bool allowMultiple: false}) { | 347 bool allowMultiple: false, bool isHidden: false}) { |
| 346 // Make sure the name isn't in use. | 348 // Make sure the name isn't in use. |
| 347 if (_options.containsKey(name)) { | 349 if (_options.containsKey(name)) { |
| 348 throw new ArgumentError('Duplicate option "$name".'); | 350 throw new ArgumentError('Duplicate option "$name".'); |
| 349 } | 351 } |
| 350 | 352 |
| 351 // Make sure the abbreviation isn't too long or in use. | 353 // Make sure the abbreviation isn't too long or in use. |
| 352 if (abbr != null) { | 354 if (abbr != null) { |
| 353 var existing = findByAbbreviation(abbr); | 355 var existing = findByAbbreviation(abbr); |
| 354 if (existing != null) { | 356 if (existing != null) { |
| 355 throw new ArgumentError( | 357 throw new ArgumentError( |
| 356 'Abbreviation "$abbr" is already used by "${existing.name}".'); | 358 'Abbreviation "$abbr" is already used by "${existing.name}".'); |
| 357 } | 359 } |
| 358 } | 360 } |
| 359 | 361 |
| 360 _options[name] = new Option(name, abbr, help, allowed, allowedHelp, | 362 _options[name] = new Option(name, abbr, help, allowed, allowedHelp, |
| 361 defaultsTo, callback, isFlag: isFlag, negatable: negatable, | 363 defaultsTo, callback, isFlag: isFlag, negatable: negatable, |
| 362 allowMultiple: allowMultiple); | 364 allowMultiple: allowMultiple, isHidden: isHidden); |
| 363 } | 365 } |
| 364 | 366 |
| 365 /** | 367 /** |
| 366 * Parses [args], a list of command-line arguments, matches them against the | 368 * Parses [args], a list of command-line arguments, matches them against the |
| 367 * flags and options defined by this parser, and returns the result. | 369 * flags and options defined by this parser, and returns the result. |
| 368 * | 370 * |
| 369 * If [allowTrailingOptions] is set, the parser will continue parsing even | 371 * If [allowTrailingOptions] is set, the parser will continue parsing even |
| 370 * after it finds an argument that is neither an option nor a command. | 372 * after it finds an argument that is neither an option nor a command. |
| 371 * This allows options to be specified after regular arguments. | 373 * This allows options to be specified after regular arguments. |
| 372 * | 374 * |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 445 'Could not find an option named "$name".'); | 447 'Could not find an option named "$name".'); |
| 446 } | 448 } |
| 447 | 449 |
| 448 return _options[name]; | 450 return _options[name]; |
| 449 } | 451 } |
| 450 | 452 |
| 451 /** Get the names of the options as an [Iterable]. */ | 453 /** Get the names of the options as an [Iterable]. */ |
| 452 Iterable<String> get options => _options.keys; | 454 Iterable<String> get options => _options.keys; |
| 453 } | 455 } |
| 454 | 456 |
| OLD | NEW |