| 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'; |
| 11 import 'dart:io'; | 11 import 'dart:io'; |
| 12 import 'dart:math'; | 12 import 'dart:math'; |
| 13 import 'io.dart'; | 13 import 'io.dart'; |
| 14 import 'command_help.dart'; | 14 import 'command_help.dart'; |
| 15 import 'command_install.dart'; | 15 import 'command_install.dart'; |
| 16 import 'command_lish.dart'; | 16 import 'command_lish.dart'; |
| 17 import 'command_update.dart'; | 17 import 'command_update.dart'; |
| 18 import 'command_version.dart'; | 18 import 'command_version.dart'; |
| 19 import 'entrypoint.dart'; | 19 import 'entrypoint.dart'; |
| 20 import 'exit_codes.dart' as exit_codes; | 20 import 'exit_codes.dart' as exit_codes; |
| 21 import 'package.dart'; | 21 import 'package.dart'; |
| 22 import 'path.dart' as path; |
| 22 import 'pubspec.dart'; | 23 import 'pubspec.dart'; |
| 23 import 'source.dart'; | 24 import 'source.dart'; |
| 24 import 'source_registry.dart'; | 25 import 'source_registry.dart'; |
| 25 import 'system_cache.dart'; | 26 import 'system_cache.dart'; |
| 26 import 'utils.dart'; | 27 import 'utils.dart'; |
| 27 import 'version.dart'; | 28 import 'version.dart'; |
| 28 | 29 |
| 29 Version get pubVersion => new Version(0, 0, 0); | 30 Version get pubVersion => new Version(0, 0, 0); |
| 30 | 31 |
| 31 /** | 32 /** |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 } | 210 } |
| 210 | 211 |
| 211 exit(_chooseExitCode(error)); | 212 exit(_chooseExitCode(error)); |
| 212 } | 213 } |
| 213 | 214 |
| 214 var future = new Future.immediate(null); | 215 var future = new Future.immediate(null); |
| 215 if (requiresEntrypoint) { | 216 if (requiresEntrypoint) { |
| 216 // TODO(rnystrom): Will eventually need better logic to walk up | 217 // TODO(rnystrom): Will eventually need better logic to walk up |
| 217 // subdirectories until we hit one that looks package-like. For now, just | 218 // subdirectories until we hit one that looks package-like. For now, just |
| 218 // assume the cwd is it. | 219 // assume the cwd is it. |
| 219 future = Entrypoint.load(currentWorkingDir, cache); | 220 future = Entrypoint.load(path.current, cache); |
| 220 } | 221 } |
| 221 | 222 |
| 222 future = future.chain((entrypoint) { | 223 future = future.chain((entrypoint) { |
| 223 this.entrypoint = entrypoint; | 224 this.entrypoint = entrypoint; |
| 224 try { | 225 try { |
| 225 var commandFuture = onRun(); | 226 var commandFuture = onRun(); |
| 226 if (commandFuture == null) return new Future.immediate(true); | 227 if (commandFuture == null) return new Future.immediate(true); |
| 227 | 228 |
| 228 return commandFuture; | 229 return commandFuture; |
| 229 } catch (error, trace) { | 230 } catch (error, trace) { |
| 230 handleError(error, trace); | 231 handleError(error, trace); |
| 231 return new Future.immediate(null); | 232 return new Future.immediate(null); |
| 232 } | 233 } |
| 233 }); | 234 }); |
| 234 | 235 |
| 235 future = future.chain((_) => cache_.deleteTempDir()); | 236 future = future.chain((_) => cache_.deleteTempDir()); |
| 236 | 237 |
| 237 future.handleException((e) { | 238 future.handleException((e) { |
| 238 if (e is PubspecNotFoundException && e.name == null) { | 239 if (e is PubspecNotFoundException && e.name == null) { |
| 239 e = 'Could not find a file named "pubspec.yaml" in the directory ' | 240 e = 'Could not find a file named "pubspec.yaml" in the directory ' |
| 240 '$currentWorkingDir.'; | 241 '${path.current}.'; |
| 241 } else if (e is PubspecHasNoNameException && e.name == null) { | 242 } else if (e is PubspecHasNoNameException && e.name == null) { |
| 242 e = 'pubspec.yaml is missing the required "name" field (e.g. "name: ' | 243 e = 'pubspec.yaml is missing the required "name" field (e.g. "name: ' |
| 243 '${basename(currentWorkingDir)}").'; | 244 '${basename(path.current)}").'; |
| 244 } | 245 } |
| 245 | 246 |
| 246 handleError(e, future.stackTrace); | 247 handleError(e, future.stackTrace); |
| 247 }); | 248 }); |
| 248 | 249 |
| 249 // Explicitly exit on success to ensure that any dangling dart:io handles | 250 // Explicitly exit on success to ensure that any dangling dart:io handles |
| 250 // don't cause the process to never terminate. | 251 // don't cause the process to never terminate. |
| 251 future.then((_) => exit(0)); | 252 future.then((_) => exit(0)); |
| 252 } | 253 } |
| 253 | 254 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 278 if (exception is HttpException || exception is HttpParserException || | 279 if (exception is HttpException || exception is HttpParserException || |
| 279 exception is SocketIOException || exception is PubHttpException) { | 280 exception is SocketIOException || exception is PubHttpException) { |
| 280 return exit_codes.UNAVAILABLE; | 281 return exit_codes.UNAVAILABLE; |
| 281 } else if (exception is FormatException) { | 282 } else if (exception is FormatException) { |
| 282 return exit_codes.DATA; | 283 return exit_codes.DATA; |
| 283 } else { | 284 } else { |
| 284 return 1; | 285 return 1; |
| 285 } | 286 } |
| 286 } | 287 } |
| 287 } | 288 } |
| OLD | NEW |