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 'errors.dart' show inputError, internalError; | 7 import 'deprecated_problems.dart' |
| 8 show deprecated_inputError, deprecated_internalProblem; |
8 | 9 |
9 argumentError(String usage, String message) { | 10 deprecated_argumentError(String usage, String message) { |
10 if (usage != null) print(usage); | 11 if (usage != null) print(usage); |
11 inputError(null, null, message); | 12 deprecated_inputError(null, null, message); |
12 } | 13 } |
13 | 14 |
14 class ParsedArguments { | 15 class ParsedArguments { |
15 final Map<String, dynamic> options = <String, dynamic>{}; | 16 final Map<String, dynamic> options = <String, dynamic>{}; |
16 final List<String> arguments = <String>[]; | 17 final List<String> arguments = <String>[]; |
17 | 18 |
18 toString() => "ParsedArguments($options, $arguments)"; | 19 toString() => "ParsedArguments($options, $arguments)"; |
19 } | 20 } |
20 | 21 |
21 class CommandLine { | 22 class CommandLine { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 nonOptions = arguments.skip(index + 1); | 82 nonOptions = arguments.skip(index + 1); |
82 iterator = arguments.take(index).iterator; | 83 iterator = arguments.take(index).iterator; |
83 } | 84 } |
84 while (iterator.moveNext()) { | 85 while (iterator.moveNext()) { |
85 String argument = iterator.current; | 86 String argument = iterator.current; |
86 if (argument.startsWith("-")) { | 87 if (argument.startsWith("-")) { |
87 var valueSpecification = specification[argument]; | 88 var valueSpecification = specification[argument]; |
88 String value; | 89 String value; |
89 if (valueSpecification != null) { | 90 if (valueSpecification != null) { |
90 if (!iterator.moveNext()) { | 91 if (!iterator.moveNext()) { |
91 return argumentError(usage, "Expected value after '$argument'."); | 92 return deprecated_argumentError( |
| 93 usage, "Expected value after '$argument'."); |
92 } | 94 } |
93 value = iterator.current; | 95 value = iterator.current; |
94 } else { | 96 } else { |
95 index = argument.indexOf("="); | 97 index = argument.indexOf("="); |
96 if (index != -1) { | 98 if (index != -1) { |
97 value = argument.substring(index + 1); | 99 value = argument.substring(index + 1); |
98 argument = argument.substring(0, index); | 100 argument = argument.substring(0, index); |
99 valueSpecification = specification[argument]; | 101 valueSpecification = specification[argument]; |
100 } | 102 } |
101 } | 103 } |
102 if (valueSpecification == null) { | 104 if (valueSpecification == null) { |
103 if (value != null) { | 105 if (value != null) { |
104 return argumentError( | 106 return deprecated_argumentError( |
105 usage, "Argument '$argument' doesn't take a value: '$value'."); | 107 usage, "Argument '$argument' doesn't take a value: '$value'."); |
106 } | 108 } |
107 result.options[argument] = true; | 109 result.options[argument] = true; |
108 } else { | 110 } else { |
109 if (valueSpecification is! String && valueSpecification is! Type) { | 111 if (valueSpecification is! String && valueSpecification is! Type) { |
110 return argumentError( | 112 return deprecated_argumentError( |
111 usage, | 113 usage, |
112 "Unrecognized type of value " | 114 "Unrecognized type of value " |
113 "specification: ${valueSpecification.runtimeType}."); | 115 "specification: ${valueSpecification.runtimeType}."); |
114 } | 116 } |
115 switch ("$valueSpecification") { | 117 switch ("$valueSpecification") { |
116 case ",": | 118 case ",": |
117 result.options | 119 result.options |
118 .putIfAbsent(argument, () => <String>[]) | 120 .putIfAbsent(argument, () => <String>[]) |
119 .addAll(value.split(",")); | 121 .addAll(value.split(",")); |
120 break; | 122 break; |
121 | 123 |
122 case "int": | 124 case "int": |
123 case "bool": | 125 case "bool": |
124 case "String": | 126 case "String": |
125 case "Uri": | 127 case "Uri": |
126 if (result.options.containsKey(argument)) { | 128 if (result.options.containsKey(argument)) { |
127 return argumentError( | 129 return deprecated_argumentError( |
128 usage, | 130 usage, |
129 "Multiple values for '$argument': " | 131 "Multiple values for '$argument': " |
130 "'${result.options[argument]}' and '$value'."); | 132 "'${result.options[argument]}' and '$value'."); |
131 } | 133 } |
132 var parsedValue; | 134 var parsedValue; |
133 if (valueSpecification == int) { | 135 if (valueSpecification == int) { |
134 parsedValue = int.parse(value, onError: (_) { | 136 parsedValue = int.parse(value, onError: (_) { |
135 return argumentError( | 137 return deprecated_argumentError( |
136 usage, "Value for '$argument', '$value', isn't an int."); | 138 usage, "Value for '$argument', '$value', isn't an int."); |
137 }); | 139 }); |
138 } else if (valueSpecification == bool) { | 140 } else if (valueSpecification == bool) { |
139 if (value == "true" || value == "yes") { | 141 if (value == "true" || value == "yes") { |
140 parsedValue = true; | 142 parsedValue = true; |
141 } else if (value == "false" || value == "no") { | 143 } else if (value == "false" || value == "no") { |
142 parsedValue = false; | 144 parsedValue = false; |
143 } else { | 145 } else { |
144 return argumentError( | 146 return deprecated_argumentError( |
145 usage, | 147 usage, |
146 "Value for '$argument' is '$value', " | 148 "Value for '$argument' is '$value', " |
147 "but expected one of: 'true', 'false', 'yes', or 'no'."); | 149 "but expected one of: 'true', 'false', 'yes', or 'no'."); |
148 } | 150 } |
149 } else if (valueSpecification == Uri) { | 151 } else if (valueSpecification == Uri) { |
150 parsedValue = Uri.base.resolve(value); | 152 parsedValue = Uri.base.resolve(value); |
151 } else if (valueSpecification == String) { | 153 } else if (valueSpecification == String) { |
152 parsedValue = value; | 154 parsedValue = value; |
153 } else if (valueSpecification is String) { | 155 } else if (valueSpecification is String) { |
154 return argumentError( | 156 return deprecated_argumentError( |
155 usage, | 157 usage, |
156 "Unrecognized value specification: " | 158 "Unrecognized value specification: " |
157 "'$valueSpecification', try using a type literal instead."); | 159 "'$valueSpecification', try using a type literal instead."); |
158 } else { | 160 } else { |
159 // All possible cases should have been handled above. | 161 // All possible cases should have been handled above. |
160 return internalError("assertion failure"); | 162 return deprecated_internalProblem("assertion failure"); |
161 } | 163 } |
162 result.options[argument] = parsedValue; | 164 result.options[argument] = parsedValue; |
163 break; | 165 break; |
164 | 166 |
165 default: | 167 default: |
166 return argumentError(usage, | 168 return deprecated_argumentError(usage, |
167 "Unrecognized value specification: '$valueSpecification'."); | 169 "Unrecognized value specification: '$valueSpecification'."); |
168 } | 170 } |
169 } | 171 } |
170 } else if (argument == "/?" || argument == "/h") { | 172 } else if (argument == "/?" || argument == "/h") { |
171 result.options[argument] = true; | 173 result.options[argument] = true; |
172 } else { | 174 } else { |
173 result.arguments.add(argument); | 175 result.arguments.add(argument); |
174 } | 176 } |
175 } | 177 } |
176 result.arguments.addAll(nonOptions); | 178 result.arguments.addAll(nonOptions); |
177 return result; | 179 return result; |
178 } | 180 } |
179 } | 181 } |
OLD | NEW |