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 /// The main entrypoint for the pub command line application. | 5 /// The main entrypoint for the pub command line application. |
6 library pub; | 6 library pub; |
7 | 7 |
| 8 import 'dart:async'; |
8 import '../../pkg/args/lib/args.dart'; | 9 import '../../pkg/args/lib/args.dart'; |
9 import '../../pkg/path/lib/path.dart' as path; | 10 import '../../pkg/path/lib/path.dart' as path; |
10 import 'dart:io'; | 11 import 'dart:io'; |
11 import 'dart:math'; | 12 import 'dart:math'; |
12 import 'http.dart'; | 13 import 'http.dart'; |
13 import 'io.dart'; | 14 import 'io.dart'; |
14 import 'command_help.dart'; | 15 import 'command_help.dart'; |
15 import 'command_install.dart'; | 16 import 'command_install.dart'; |
16 import 'command_lish.dart'; | 17 import 'command_lish.dart'; |
17 import 'command_update.dart'; | 18 import 'command_update.dart'; |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 } | 238 } |
238 | 239 |
239 var future = new Future.immediate(null); | 240 var future = new Future.immediate(null); |
240 if (requiresEntrypoint) { | 241 if (requiresEntrypoint) { |
241 // TODO(rnystrom): Will eventually need better logic to walk up | 242 // TODO(rnystrom): Will eventually need better logic to walk up |
242 // subdirectories until we hit one that looks package-like. For now, just | 243 // subdirectories until we hit one that looks package-like. For now, just |
243 // assume the cwd is it. | 244 // assume the cwd is it. |
244 future = Entrypoint.load(path.current, cache); | 245 future = Entrypoint.load(path.current, cache); |
245 } | 246 } |
246 | 247 |
247 future = future.chain((entrypoint) { | 248 future = future.then((entrypoint) { |
248 this.entrypoint = entrypoint; | 249 this.entrypoint = entrypoint; |
249 try { | 250 try { |
250 var commandFuture = onRun(); | 251 var commandFuture = onRun(); |
251 if (commandFuture == null) return new Future.immediate(true); | 252 if (commandFuture == null) return new Future.immediate(true); |
252 | 253 |
253 return commandFuture; | 254 return commandFuture; |
254 } catch (error, trace) { | 255 } catch (error, trace) { |
255 handleError(error, trace); | 256 handleError(error, trace); |
256 return new Future.immediate(null); | 257 return new Future.immediate(null); |
257 } | 258 } |
258 }); | 259 }); |
259 | 260 |
260 future = future.chain((_) => cache_.deleteTempDir()); | |
261 | 261 |
262 future.handleException((e) { | 262 future |
263 if (e is PubspecNotFoundException && e.name == null) { | 263 .then((_) => cache_.deleteTempDir()) |
264 e = 'Could not find a file named "pubspec.yaml" in the directory ' | 264 .catchError((error) { |
265 '${path.current}.'; | 265 var e = error.error; |
266 } else if (e is PubspecHasNoNameException && e.name == null) { | 266 if (e is PubspecNotFoundException && e.name == null) { |
267 e = 'pubspec.yaml is missing the required "name" field (e.g. "name: ' | 267 e = 'Could not find a file named "pubspec.yaml" in the directory ' |
268 '${basename(path.current)}").'; | 268 '${path.current}.'; |
269 } | 269 } else if (e is PubspecHasNoNameException && e.name == null) { |
| 270 e = 'pubspec.yaml is missing the required "name" field (e.g. "name: ' |
| 271 '${basename(path.current)}").'; |
| 272 } |
270 | 273 |
271 handleError(e, future.stackTrace); | 274 handleError(e, error.stackTrace); |
272 }); | 275 }) |
273 | 276 // Explicitly exit on success to ensure that any dangling dart:io handles |
274 // Explicitly exit on success to ensure that any dangling dart:io handles | 277 // don't cause the process to never terminate. |
275 // don't cause the process to never terminate. | 278 .then((_) => exit(0)); |
276 future.then((_) => exit(0)); | |
277 } | 279 } |
278 | 280 |
279 /// Override this to perform the specific command. Return a future that | 281 /// Override this to perform the specific command. Return a future that |
280 /// completes when the command is done or fails if the command fails. If the | 282 /// completes when the command is done or fails if the command fails. If the |
281 /// command is synchronous, it may return `null`. | 283 /// command is synchronous, it may return `null`. |
282 Future onRun(); | 284 Future onRun(); |
283 | 285 |
284 /// Displays usage information for this command. | 286 /// Displays usage information for this command. |
285 void printUsage([String description]) { | 287 void printUsage([String description]) { |
286 if (description == null) description = this.description; | 288 if (description == null) description = this.description; |
(...skipping 16 matching lines...) Expand all Loading... |
303 if (exception is HttpException || exception is HttpParserException || | 305 if (exception is HttpException || exception is HttpParserException || |
304 exception is SocketIOException || exception is PubHttpException) { | 306 exception is SocketIOException || exception is PubHttpException) { |
305 return exit_codes.UNAVAILABLE; | 307 return exit_codes.UNAVAILABLE; |
306 } else if (exception is FormatException) { | 308 } else if (exception is FormatException) { |
307 return exit_codes.DATA; | 309 return exit_codes.DATA; |
308 } else { | 310 } else { |
309 return 1; | 311 return 1; |
310 } | 312 } |
311 } | 313 } |
312 } | 314 } |
OLD | NEW |