| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library args.src.arg_parser; | 5 library args.src.arg_parser; |
| 6 | 6 |
| 7 import 'package:collection/wrappers.dart'; | 7 import 'package:collection/wrappers.dart'; |
| 8 | 8 |
| 9 import 'arg_results.dart'; | 9 import 'arg_results.dart'; |
| 10 import 'option.dart'; | 10 import 'option.dart'; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 } | 108 } |
| 109 | 109 |
| 110 /// Parses [args], a list of command-line arguments, matches them against the | 110 /// Parses [args], a list of command-line arguments, matches them against the |
| 111 /// flags and options defined by this parser, and returns the result. | 111 /// flags and options defined by this parser, and returns the result. |
| 112 ArgResults parse(List<String> args) => | 112 ArgResults parse(List<String> args) => |
| 113 new Parser(null, this, args.toList(), null, null).parse(); | 113 new Parser(null, this, args.toList(), null, null).parse(); |
| 114 | 114 |
| 115 /// Generates a string displaying usage information for the defined options. | 115 /// Generates a string displaying usage information for the defined options. |
| 116 /// | 116 /// |
| 117 /// This is basically the help text shown on the command line. | 117 /// This is basically the help text shown on the command line. |
| 118 @Deprecated("Replaced with get usage. getUsage() will be removed in args 1.0") |
| 118 String getUsage() => new Usage(this).generate(); | 119 String getUsage() => new Usage(this).generate(); |
| 119 | 120 |
| 121 /// Generates a string displaying usage information for the defined options. |
| 122 /// |
| 123 /// This is basically the help text shown on the command line. |
| 124 String get usage => new Usage(this).generate(); |
| 125 |
| 120 /// Get the default value for an option. Useful after parsing to test if the | 126 /// Get the default value for an option. Useful after parsing to test if the |
| 121 /// user specified something other than the default. | 127 /// user specified something other than the default. |
| 122 getDefault(String option) { | 128 getDefault(String option) { |
| 123 if (!options.containsKey(option)) { | 129 if (!options.containsKey(option)) { |
| 124 throw new ArgumentError('No option named $option'); | 130 throw new ArgumentError('No option named $option'); |
| 125 } | 131 } |
| 126 return options[option].defaultValue; | 132 return options[option].defaultValue; |
| 127 } | 133 } |
| 128 | 134 |
| 129 /// Finds the option whose abbreviation is [abbr], or `null` if no option has | 135 /// Finds the option whose abbreviation is [abbr], or `null` if no option has |
| 130 /// that abbreviation. | 136 /// that abbreviation. |
| 131 Option findByAbbreviation(String abbr) { | 137 Option findByAbbreviation(String abbr) { |
| 132 return options.values.firstWhere((option) => option.abbreviation == abbr, | 138 return options.values.firstWhere((option) => option.abbreviation == abbr, |
| 133 orElse: () => null); | 139 orElse: () => null); |
| 134 } | 140 } |
| 135 } | 141 } |
| OLD | NEW |