| 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 'dart:async'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 import 'dart:math'; | 10 import 'dart:math'; |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 globalOptions = globalOptions_; | 229 globalOptions = globalOptions_; |
| 230 | 230 |
| 231 try { | 231 try { |
| 232 commandOptions = commandParser.parse(commandArgs); | 232 commandOptions = commandParser.parse(commandArgs); |
| 233 } on FormatException catch (e) { | 233 } on FormatException catch (e) { |
| 234 log.error(e.message); | 234 log.error(e.message); |
| 235 log.error('Use "pub help" for more information.'); | 235 log.error('Use "pub help" for more information.'); |
| 236 exit(exit_codes.USAGE); | 236 exit(exit_codes.USAGE); |
| 237 } | 237 } |
| 238 | 238 |
| 239 handleError(error, trace) { | 239 handleError(error) { |
| 240 var trace = getAttachedStackTrace(error); |
| 241 |
| 240 // This is basically the top-level exception handler so that we don't | 242 // This is basically the top-level exception handler so that we don't |
| 241 // spew a stack trace on our users. | 243 // spew a stack trace on our users. |
| 242 var message; | 244 var message; |
| 243 | 245 |
| 244 try { | 246 try { |
| 245 // Most exception types have a "message" property. We prefer this since | 247 // Most exception types have a "message" property. We prefer this since |
| 246 // it skips the "Exception:", "HttpException:", etc. prefix that calling | 248 // it skips the "Exception:", "HttpException:", etc. prefix that calling |
| 247 // toString() adds. But, alas, "message" isn't actually defined in the | 249 // toString() adds. But, alas, "message" isn't actually defined in the |
| 248 // base Exception type so there's no easy way to know if it's available | 250 // base Exception type so there's no easy way to know if it's available |
| 249 // short of a giant pile of type tests for each known exception type. | 251 // short of a giant pile of type tests for each known exception type. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 270 // TODO(rnystrom): Will eventually need better logic to walk up | 272 // TODO(rnystrom): Will eventually need better logic to walk up |
| 271 // subdirectories until we hit one that looks package-like. For now, | 273 // subdirectories until we hit one that looks package-like. For now, |
| 272 // just assume the cwd is it. | 274 // just assume the cwd is it. |
| 273 entrypoint = new Entrypoint(path.current, cache); | 275 entrypoint = new Entrypoint(path.current, cache); |
| 274 } | 276 } |
| 275 | 277 |
| 276 var commandFuture = onRun(); | 278 var commandFuture = onRun(); |
| 277 if (commandFuture == null) return true; | 279 if (commandFuture == null) return true; |
| 278 | 280 |
| 279 return commandFuture; | 281 return commandFuture; |
| 280 }).whenComplete(() => cache_.deleteTempDir()).catchError((asyncError) { | 282 }).whenComplete(() => cache_.deleteTempDir()).catchError((e) { |
| 281 var e = asyncError.error; | |
| 282 if (e is PubspecNotFoundException && e.name == null) { | 283 if (e is PubspecNotFoundException && e.name == null) { |
| 283 e = 'Could not find a file named "pubspec.yaml" in the directory ' | 284 e = 'Could not find a file named "pubspec.yaml" in the directory ' |
| 284 '${path.current}.'; | 285 '${path.current}.'; |
| 285 } else if (e is PubspecHasNoNameException && e.name == null) { | 286 } else if (e is PubspecHasNoNameException && e.name == null) { |
| 286 e = 'pubspec.yaml is missing the required "name" field (e.g. "name: ' | 287 e = 'pubspec.yaml is missing the required "name" field (e.g. "name: ' |
| 287 '${path.basename(path.current)}").'; | 288 '${path.basename(path.current)}").'; |
| 288 } | 289 } |
| 289 | 290 |
| 290 handleError(e, asyncError.stackTrace); | 291 handleError(e); |
| 291 }).then((_) { | 292 }).then((_) { |
| 292 // Explicitly exit on success to ensure that any dangling dart:io handles | 293 // Explicitly exit on success to ensure that any dangling dart:io handles |
| 293 // don't cause the process to never terminate. | 294 // don't cause the process to never terminate. |
| 294 exit(0); | 295 exit(0); |
| 295 }); | 296 }); |
| 296 } | 297 } |
| 297 | 298 |
| 298 /// Override this to perform the specific command. Return a future that | 299 /// Override this to perform the specific command. Return a future that |
| 299 /// completes when the command is done or fails if the command fails. If the | 300 /// completes when the command is done or fails if the command fails. If the |
| 300 /// command is synchronous, it may return `null`. | 301 /// command is synchronous, it may return `null`. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 322 if (exception is HttpException || exception is HttpParserException || | 323 if (exception is HttpException || exception is HttpParserException || |
| 323 exception is SocketIOException || exception is PubHttpException) { | 324 exception is SocketIOException || exception is PubHttpException) { |
| 324 return exit_codes.UNAVAILABLE; | 325 return exit_codes.UNAVAILABLE; |
| 325 } else if (exception is FormatException) { | 326 } else if (exception is FormatException) { |
| 326 return exit_codes.DATA; | 327 return exit_codes.DATA; |
| 327 } else { | 328 } else { |
| 328 return 1; | 329 return 1; |
| 329 } | 330 } |
| 330 } | 331 } |
| 331 } | 332 } |
| OLD | NEW |