| 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 import 'dart:collection'; | 5 import 'dart:collection'; |
| 6 | 6 |
| 7 import 'arg_results.dart'; | 7 import 'arg_results.dart'; |
| 8 import 'option.dart'; | 8 import 'option.dart'; |
| 9 import 'parser.dart'; | 9 import 'parser.dart'; |
| 10 import 'usage.dart'; | 10 import 'usage.dart'; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 /// | 123 /// |
| 124 /// In the usage text for the parser, this will appear between any options | 124 /// In the usage text for the parser, this will appear between any options |
| 125 /// added before this call and ones added after it. | 125 /// added before this call and ones added after it. |
| 126 void addSeparator(String text) { | 126 void addSeparator(String text) { |
| 127 _optionsAndSeparators.add(text); | 127 _optionsAndSeparators.add(text); |
| 128 } | 128 } |
| 129 | 129 |
| 130 /// Parses [args], a list of command-line arguments, matches them against the | 130 /// Parses [args], a list of command-line arguments, matches them against the |
| 131 /// flags and options defined by this parser, and returns the result. | 131 /// flags and options defined by this parser, and returns the result. |
| 132 ArgResults parse(List<String> args) => | 132 ArgResults parse(List<String> args) => |
| 133 new Parser(null, this, args.toList(), null, null).parse(); | 133 new Parser(null, this, args.toList()).parse(); |
| 134 | 134 |
| 135 /// Generates a string displaying usage information for the defined options. | 135 /// Generates a string displaying usage information for the defined options. |
| 136 /// | 136 /// |
| 137 /// This is basically the help text shown on the command line. | 137 /// This is basically the help text shown on the command line. |
| 138 @Deprecated("Replaced with get usage. getUsage() will be removed in args 1.0") | 138 @Deprecated("Replaced with get usage. getUsage() will be removed in args 1.0") |
| 139 String getUsage() => usage; | 139 String getUsage() => usage; |
| 140 | 140 |
| 141 /// Generates a string displaying usage information for the defined options. | 141 /// Generates a string displaying usage information for the defined options. |
| 142 /// | 142 /// |
| 143 /// This is basically the help text shown on the command line. | 143 /// This is basically the help text shown on the command line. |
| 144 String get usage => new Usage(_optionsAndSeparators).generate(); | 144 String get usage => new Usage(_optionsAndSeparators).generate(); |
| 145 | 145 |
| 146 /// Get the default value for an option. Useful after parsing to test if the | 146 /// Get the default value for an option. Useful after parsing to test if the |
| 147 /// user specified something other than the default. | 147 /// user specified something other than the default. |
| 148 getDefault(String option) { | 148 getDefault(String option) { |
| 149 if (!options.containsKey(option)) { | 149 if (!options.containsKey(option)) { |
| 150 throw new ArgumentError('No option named $option'); | 150 throw new ArgumentError('No option named $option'); |
| 151 } | 151 } |
| 152 return options[option].defaultValue; | 152 return options[option].defaultValue; |
| 153 } | 153 } |
| 154 | 154 |
| 155 /// Finds the option whose abbreviation is [abbr], or `null` if no option has | 155 /// Finds the option whose abbreviation is [abbr], or `null` if no option has |
| 156 /// that abbreviation. | 156 /// that abbreviation. |
| 157 Option findByAbbreviation(String abbr) { | 157 Option findByAbbreviation(String abbr) { |
| 158 return options.values.firstWhere((option) => option.abbreviation == abbr, | 158 return options.values.firstWhere((option) => option.abbreviation == abbr, |
| 159 orElse: () => null); | 159 orElse: () => null); |
| 160 } | 160 } |
| 161 } | 161 } |
| OLD | NEW |