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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:io'; | 6 import 'dart:io'; |
7 | 7 |
8 import 'package:args/args.dart'; | 8 import 'package:args/args.dart'; |
9 import 'package:http/http.dart' as http; | 9 import 'package:http/http.dart' as http; |
10 import 'package:path/path.dart' as path; | 10 import 'package:path/path.dart' as path; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 } else if (exception is FormatException || exception is DataException) { | 122 } else if (exception is FormatException || exception is DataException) { |
123 return exit_codes.DATA; | 123 return exit_codes.DATA; |
124 } else if (exception is UsageException) { | 124 } else if (exception is UsageException) { |
125 return exit_codes.USAGE; | 125 return exit_codes.USAGE; |
126 } else { | 126 } else { |
127 return 1; | 127 return 1; |
128 } | 128 } |
129 } | 129 } |
130 | 130 |
131 /// Walks the command tree and runs the selected pub command. | 131 /// Walks the command tree and runs the selected pub command. |
132 Future invokeCommand(String cacheDir, ArgResults mainOptions) { | 132 Future invokeCommand(String cacheDir, ArgResults mainOptions) async { |
133 var commands = PubCommand.mainCommands; | 133 var commands = PubCommand.mainCommands; |
134 var command; | 134 var command; |
135 var commandString = "pub"; | 135 var commandString = "pub"; |
136 var options = mainOptions; | 136 var options = mainOptions; |
137 | 137 |
138 while (commands.isNotEmpty) { | 138 while (commands.isNotEmpty) { |
139 if (options.command == null) { | 139 if (options.command == null) { |
140 if (options.rest.isEmpty) { | 140 if (options.rest.isEmpty) { |
141 if (command == null) { | 141 if (command == null) { |
142 // No top-level command was chosen. | 142 // No top-level command was chosen. |
(...skipping 24 matching lines...) Expand all Loading... |
167 return new Future.value(); | 167 return new Future.value(); |
168 } | 168 } |
169 } | 169 } |
170 | 170 |
171 // Make sure there aren't unexpected arguments. | 171 // Make sure there aren't unexpected arguments. |
172 if (!command.takesArguments && options.rest.isNotEmpty) { | 172 if (!command.takesArguments && options.rest.isNotEmpty) { |
173 command.usageError( | 173 command.usageError( |
174 'Command "${options.name}" does not take any arguments.'); | 174 'Command "${options.name}" does not take any arguments.'); |
175 } | 175 } |
176 | 176 |
177 return syncFuture(() { | 177 try { |
| 178 // TODO(rnystrom): Use await here when this is fixed: |
| 179 // https://github.com/dart-lang/async_await/issues/40. |
178 return command.run(cacheDir, mainOptions, options); | 180 return command.run(cacheDir, mainOptions, options); |
179 }).whenComplete(() { | 181 } finally { |
180 command.cache.deleteTempDir(); | 182 command.cache.deleteTempDir(); |
181 }); | 183 } |
182 } | 184 } |
183 | 185 |
184 /// Checks that pub is running on a supported platform. | 186 /// Checks that pub is running on a supported platform. |
185 /// | 187 /// |
186 /// If it isn't, it prints an error message and exits. Completes when the | 188 /// If it isn't, it prints an error message and exits. Completes when the |
187 /// validation is done. | 189 /// validation is done. |
188 Future validatePlatform() { | 190 Future validatePlatform() async { |
189 return syncFuture(() { | 191 if (Platform.operatingSystem != 'windows') return; |
190 if (Platform.operatingSystem != 'windows') return null; | |
191 | 192 |
192 return runProcess('ver', []).then((result) { | 193 var result = await runProcess('ver', []); |
193 if (result.stdout.join('\n').contains('XP')) { | 194 if (result.stdout.join('\n').contains('XP')) { |
194 log.error('Sorry, but pub is not supported on Windows XP.'); | 195 log.error('Sorry, but pub is not supported on Windows XP.'); |
195 return flushThenExit(exit_codes.USAGE); | 196 await flushThenExit(exit_codes.USAGE); |
196 } | 197 } |
197 }); | |
198 }); | |
199 } | 198 } |
OLD | NEW |