| 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 'git_source.dart'; | |
| 22 import 'hosted_source.dart'; | |
| 23 import 'package.dart'; | 21 import 'package.dart'; |
| 24 import 'pubspec.dart'; | 22 import 'pubspec.dart'; |
| 25 import 'sdk_source.dart'; | |
| 26 import 'source.dart'; | 23 import 'source.dart'; |
| 27 import 'source_registry.dart'; | 24 import 'source_registry.dart'; |
| 28 import 'system_cache.dart'; | 25 import 'system_cache.dart'; |
| 29 import 'utils.dart'; | 26 import 'utils.dart'; |
| 30 import 'version.dart'; | 27 import 'version.dart'; |
| 31 | 28 |
| 32 Version get pubVersion => new Version(0, 0, 0); | 29 Version get pubVersion => new Version(0, 0, 0); |
| 33 | 30 |
| 34 /** | 31 /** |
| 35 * The commands that Pub understands. | 32 * The commands that Pub understands. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 var cacheDir; | 87 var cacheDir; |
| 91 if (Platform.environment.containsKey('PUB_CACHE')) { | 88 if (Platform.environment.containsKey('PUB_CACHE')) { |
| 92 cacheDir = Platform.environment['PUB_CACHE']; | 89 cacheDir = Platform.environment['PUB_CACHE']; |
| 93 } else if (Platform.operatingSystem == 'windows') { | 90 } else if (Platform.operatingSystem == 'windows') { |
| 94 var appData = Platform.environment['APPDATA']; | 91 var appData = Platform.environment['APPDATA']; |
| 95 cacheDir = join(appData, 'Pub', 'Cache'); | 92 cacheDir = join(appData, 'Pub', 'Cache'); |
| 96 } else { | 93 } else { |
| 97 cacheDir = '${Platform.environment['HOME']}/.pub-cache'; | 94 cacheDir = '${Platform.environment['HOME']}/.pub-cache'; |
| 98 } | 95 } |
| 99 | 96 |
| 100 var cache = new SystemCache(cacheDir); | 97 var cache = new SystemCache.withSources(cacheDir, sdkDir); |
| 101 cache.register(new SdkSource(sdkDir)); | |
| 102 cache.register(new GitSource()); | |
| 103 cache.register(new HostedSource()); | |
| 104 cache.sources.setDefault('hosted'); | |
| 105 | 98 |
| 106 // Select the command. | 99 // Select the command. |
| 107 var command = pubCommands[globalOptions.rest[0]]; | 100 var command = pubCommands[globalOptions.rest[0]]; |
| 108 if (command == null) { | 101 if (command == null) { |
| 109 printError('Could not find a command named "${globalOptions.rest[0]}".'); | 102 printError('Could not find a command named "${globalOptions.rest[0]}".'); |
| 110 printError('Run "pub help" to see available commands.'); | 103 printError('Run "pub help" to see available commands.'); |
| 111 exit(exit_codes.USAGE); | 104 exit(exit_codes.USAGE); |
| 112 return; | 105 return; |
| 113 } | 106 } |
| 114 | 107 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 } | 209 } |
| 217 | 210 |
| 218 exit(_chooseExitCode(error)); | 211 exit(_chooseExitCode(error)); |
| 219 } | 212 } |
| 220 | 213 |
| 221 var future = new Future.immediate(null); | 214 var future = new Future.immediate(null); |
| 222 if (requiresEntrypoint) { | 215 if (requiresEntrypoint) { |
| 223 // TODO(rnystrom): Will eventually need better logic to walk up | 216 // TODO(rnystrom): Will eventually need better logic to walk up |
| 224 // subdirectories until we hit one that looks package-like. For now, just | 217 // subdirectories until we hit one that looks package-like. For now, just |
| 225 // assume the cwd is it. | 218 // assume the cwd is it. |
| 226 future = Package.load(null, currentWorkingDir, cache.sources) | 219 future = Entrypoint.load(currentWorkingDir, cache); |
| 227 .transform((package) => new Entrypoint(package, cache)); | |
| 228 } | 220 } |
| 229 | 221 |
| 230 future = future.chain((entrypoint) { | 222 future = future.chain((entrypoint) { |
| 231 this.entrypoint = entrypoint; | 223 this.entrypoint = entrypoint; |
| 232 try { | 224 try { |
| 233 var commandFuture = onRun(); | 225 var commandFuture = onRun(); |
| 234 if (commandFuture == null) return new Future.immediate(true); | 226 if (commandFuture == null) return new Future.immediate(true); |
| 235 | 227 |
| 236 return commandFuture; | 228 return commandFuture; |
| 237 } catch (error, trace) { | 229 } catch (error, trace) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 if (exception is HttpException || exception is HttpParserException || | 278 if (exception is HttpException || exception is HttpParserException || |
| 287 exception is SocketIOException || exception is PubHttpException) { | 279 exception is SocketIOException || exception is PubHttpException) { |
| 288 return exit_codes.UNAVAILABLE; | 280 return exit_codes.UNAVAILABLE; |
| 289 } else if (exception is FormatException) { | 281 } else if (exception is FormatException) { |
| 290 return exit_codes.DATA; | 282 return exit_codes.DATA; |
| 291 } else { | 283 } else { |
| 292 return 1; | 284 return 1; |
| 293 } | 285 } |
| 294 } | 286 } |
| 295 } | 287 } |
| OLD | NEW |