OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 fasta.command_line; | 5 library fasta.command_line; |
6 | 6 |
7 import 'fasta_codes.dart' show Message, templateFastaCLIArgumentRequired; | 7 import 'fasta_codes.dart' show Message, templateFastaCLIArgumentRequired; |
8 | 8 |
9 import 'deprecated_problems.dart' show deprecated_inputError; | 9 import 'deprecated_problems.dart' show deprecated_inputError; |
10 | 10 |
11 import 'problems.dart' show unhandled; | 11 import 'problems.dart' show unhandled; |
12 | 12 |
13 deprecated_argumentError(Message usage, String message) { | 13 deprecated_argumentError(Message usage, String message) { |
14 if (usage != null) print(usage.message); | 14 if (usage != null) print(usage.message); |
15 deprecated_inputError(null, null, message); | 15 deprecated_inputError(null, null, message); |
16 } | 16 } |
17 | 17 |
18 argumentError(Message usage, Message message) { | 18 argumentError(Message usage, Message message) { |
19 if (usage != null) print(usage.message); | 19 if (usage != null) print(usage.message); |
20 deprecated_inputError(null, null, message.message); | 20 deprecated_inputError(null, null, message.message); |
21 } | 21 } |
22 | 22 |
23 class ParsedArguments { | 23 class ParsedArguments { |
24 final Map<String, dynamic> options = <String, dynamic>{}; | 24 final Map<String, dynamic> options = <String, dynamic>{}; |
25 final List<String> arguments = <String>[]; | 25 final List<String> arguments = <String>[]; |
26 | 26 |
27 toString() => "ParsedArguments($options, $arguments)"; | 27 toString() => "ParsedArguments($options, $arguments)"; |
28 } | 28 } |
29 | 29 |
| 30 /// Abstract parser for command-line options. |
30 class CommandLine { | 31 class CommandLine { |
31 final Map<String, dynamic> options; | 32 final Map<String, dynamic> options; |
32 | 33 |
33 final List<String> arguments; | 34 final List<String> arguments; |
34 | 35 |
35 final Message usage; | 36 final Message usage; |
36 | 37 |
37 CommandLine.parsed(ParsedArguments p, this.usage) | 38 CommandLine.parsed(ParsedArguments p, this.usage) |
38 : this.options = p.options, | 39 : this.options = p.options, |
39 this.arguments = p.arguments { | 40 this.arguments = p.arguments { |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 } else if (argument == "/?" || argument == "/h") { | 182 } else if (argument == "/?" || argument == "/h") { |
182 result.options[argument] = true; | 183 result.options[argument] = true; |
183 } else { | 184 } else { |
184 result.arguments.add(argument); | 185 result.arguments.add(argument); |
185 } | 186 } |
186 } | 187 } |
187 result.arguments.addAll(nonOptions); | 188 result.arguments.addAll(nonOptions); |
188 return result; | 189 return result; |
189 } | 190 } |
190 } | 191 } |
OLD | NEW |