OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** | 5 /** |
6 * The main entrypoint for the pub command line application. | 6 * The main entrypoint for the pub command line application. |
7 */ | 7 */ |
8 library pub; | 8 library pub; |
9 | 9 |
10 import '../../pkg/args/lib/args.dart'; | 10 import '../../pkg/args/lib/args.dart'; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 // Select the command. | 95 // Select the command. |
96 var command = pubCommands[globalOptions.rest[0]]; | 96 var command = pubCommands[globalOptions.rest[0]]; |
97 if (command == null) { | 97 if (command == null) { |
98 printError('Unknown command "${globalOptions.rest[0]}".'); | 98 printError('Unknown command "${globalOptions.rest[0]}".'); |
99 printError('Run "pub help" to see available commands.'); | 99 printError('Run "pub help" to see available commands.'); |
100 exit(exit_codes.USAGE); | 100 exit(exit_codes.USAGE); |
101 return; | 101 return; |
102 } | 102 } |
103 | 103 |
104 var commandArgs = | 104 var commandArgs = |
105 globalOptions.rest.getRange(1, globalOptions.rest.length - 1); | 105 globalOptions.rest.getRange(1, globalOptions.rest.length - 1); |
106 command.run(cache, globalOptions, commandArgs); | 106 command.run(cache, globalOptions, commandArgs); |
107 } | 107 } |
108 | 108 |
109 /** Displays usage information for the app. */ | 109 /** Displays usage information for the app. */ |
110 void printUsage([String description = 'Pub is a package manager for Dart.']) { | 110 void printUsage([String description = 'Pub is a package manager for Dart.']) { |
111 print(description); | 111 print(description); |
112 print(''); | 112 print(''); |
113 print('Usage: pub command [arguments]'); | 113 print('Usage: pub command [arguments]'); |
114 print(''); | 114 print(''); |
115 print('Global options:'); | 115 print('Global options:'); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 var commandFuture = onRun(); | 214 var commandFuture = onRun(); |
215 if (commandFuture == null) return new Future.immediate(true); | 215 if (commandFuture == null) return new Future.immediate(true); |
216 | 216 |
217 return commandFuture; | 217 return commandFuture; |
218 } catch (error, trace) { | 218 } catch (error, trace) { |
219 handleError(error, trace); | 219 handleError(error, trace); |
220 return new Future.immediate(null); | 220 return new Future.immediate(null); |
221 } | 221 } |
222 }); | 222 }); |
223 | 223 |
| 224 future = future.chain((_) => cache_.deleteTempDir()); |
| 225 |
224 future.handleException((e) { | 226 future.handleException((e) { |
225 if (e is PubspecNotFoundException && e.name == null) { | 227 if (e is PubspecNotFoundException && e.name == null) { |
226 e = 'Could not find a file named "pubspec.yaml" in the directory ' | 228 e = 'Could not find a file named "pubspec.yaml" in the directory ' |
227 '$workingDir.'; | 229 '$workingDir.'; |
228 } else if (e is PubspecHasNoNameException && e.name == null) { | 230 } else if (e is PubspecHasNoNameException && e.name == null) { |
229 e = 'pubspec.yaml is missing the required "name" field (e.g. "name: ' | 231 e = 'pubspec.yaml is missing the required "name" field (e.g. "name: ' |
230 '${basename(workingDir)}").'; | 232 '${basename(workingDir)}").'; |
231 } | 233 } |
232 | 234 |
233 handleError(e, future.stackTrace); | 235 handleError(e, future.stackTrace); |
234 }); | 236 }); |
| 237 |
235 // Explicitly exit on success to ensure that any dangling dart:io handles | 238 // Explicitly exit on success to ensure that any dangling dart:io handles |
236 // don't cause the process to never terminate. | 239 // don't cause the process to never terminate. |
237 future.then((_) => exit(0)); | 240 future.then((_) => exit(0)); |
238 } | 241 } |
239 | 242 |
240 /** | 243 /** |
241 * Override this to perform the specific command. Return a future that | 244 * Override this to perform the specific command. Return a future that |
242 * completes when the command is done or fails if the command fails. If the | 245 * completes when the command is done or fails if the command fails. If the |
243 * command is synchronous, it may return `null`. | 246 * command is synchronous, it may return `null`. |
244 */ | 247 */ |
(...skipping 19 matching lines...) Expand all Loading... |
264 if (exception is HttpException || exception is HttpParserException || | 267 if (exception is HttpException || exception is HttpParserException || |
265 exception is SocketIOException || exception is PubHttpException) { | 268 exception is SocketIOException || exception is PubHttpException) { |
266 return exit_codes.UNAVAILABLE; | 269 return exit_codes.UNAVAILABLE; |
267 } else if (exception is FormatException) { | 270 } else if (exception is FormatException) { |
268 return exit_codes.DATA; | 271 return exit_codes.DATA; |
269 } else { | 272 } else { |
270 return 1; | 273 return 1; |
271 } | 274 } |
272 } | 275 } |
273 } | 276 } |
OLD | NEW |