| 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('yaml/yaml.dart'); | 10 #import('yaml/yaml.dart'); |
| 11 | 11 |
| 12 #import('io.dart'); | 12 #import('io.dart'); |
| 13 #import('utils.dart'); | 13 #import('utils.dart'); |
| 14 | 14 |
| 15 #source('system_cache.dart'); | 15 #source('system_cache.dart'); |
| 16 #source('packages_dir.dart'); | 16 #source('packages_dir.dart'); |
| 17 #source('command_list.dart'); | 17 #source('command_list.dart'); |
| 18 #source('command_install.dart'); | 18 #source('command_install.dart'); |
| 19 #source('command_update.dart'); | 19 #source('command_update.dart'); |
| 20 #source('command_version.dart'); | 20 #source('command_version.dart'); |
| 21 #source('package.dart'); | 21 #source('package.dart'); |
| 22 #source('source.dart'); | 22 #source('source.dart'); |
| 23 #source('source_registry.dart'); |
| 23 #source('sdk_source.dart'); | 24 #source('sdk_source.dart'); |
| 25 #source('git_source.dart'); |
| 24 | 26 |
| 25 main() { | 27 main() { |
| 26 final args = new Options().arguments; | 28 final args = new Options().arguments; |
| 27 | 29 |
| 28 // TODO(rnystrom): In addition to explicit "help" and "version" commands, | 30 // TODO(rnystrom): In addition to explicit "help" and "version" commands, |
| 29 // should also add special-case support for --help and --version arguments to | 31 // should also add special-case support for --help and --version arguments to |
| 30 // be consistent with other Unix apps. | 32 // be consistent with other Unix apps. |
| 31 final commands = { | 33 final commands = { |
| 32 'list': new ListCommand(), | 34 'list': new ListCommand(), |
| 33 'install': new InstallCommand(), | 35 'install': new InstallCommand(), |
| (...skipping 29 matching lines...) Expand all Loading... |
| 63 printUsage(commands); | 65 printUsage(commands); |
| 64 return; | 66 return; |
| 65 } | 67 } |
| 66 | 68 |
| 67 if (args[0] == '--version') { | 69 if (args[0] == '--version') { |
| 68 printVersion(); | 70 printVersion(); |
| 69 return; | 71 return; |
| 70 } | 72 } |
| 71 } | 73 } |
| 72 | 74 |
| 73 // TODO(rnystrom): Do we want this to be global? | |
| 74 final cache = new SystemCache(cacheDir); | 75 final cache = new SystemCache(cacheDir); |
| 75 | 76 cache.sources.register(new SdkSource(sdkDir)); |
| 76 Source.defaultSource = new SdkSource(sdkDir); | 77 cache.sources.register(new GitSource()); |
| 78 cache.sources.setDefault('sdk'); |
| 77 | 79 |
| 78 // Select the command. | 80 // Select the command. |
| 79 final command = commands[args[0]]; | 81 final command = commands[args[0]]; |
| 80 if (command == null) { | 82 if (command == null) { |
| 81 print('Unknown command "${args[0]}".'); | 83 print('Unknown command "${args[0]}".'); |
| 82 print('Run "pub help" to see available commands.'); | 84 print('Run "pub help" to see available commands.'); |
| 83 exit(64); // See http://www.freebsd.org/cgi/man.cgi?query=sysexits. | 85 exit(64); // See http://www.freebsd.org/cgi/man.cgi?query=sysexits. |
| 84 return; | 86 return; |
| 85 } | 87 } |
| 86 | 88 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 | 132 |
| 131 void run(SystemCache cache_, List<String> args) { | 133 void run(SystemCache cache_, List<String> args) { |
| 132 cache = cache_; | 134 cache = cache_; |
| 133 | 135 |
| 134 // TODO(rnystrom): Each command should define the arguments it expects and | 136 // TODO(rnystrom): Each command should define the arguments it expects and |
| 135 // we can handle them generically here. | 137 // we can handle them generically here. |
| 136 | 138 |
| 137 // TODO(rnystrom): Will eventually need better logic to walk up | 139 // TODO(rnystrom): Will eventually need better logic to walk up |
| 138 // subdirectories until we hit one that looks package-like. For now, just | 140 // subdirectories until we hit one that looks package-like. For now, just |
| 139 // assume the cwd is it. | 141 // assume the cwd is it. |
| 140 Package.load(workingDir).then((pkg) { | 142 Package.load(workingDir, cache.sources).then((pkg) { |
| 141 packagesDir = new PackagesDir(pkg, cache); | 143 packagesDir = new PackagesDir(pkg, cache); |
| 142 onRun(); | 144 onRun(); |
| 143 }); | 145 }); |
| 144 } | 146 } |
| 145 | 147 |
| 146 abstract void onRun(); | 148 abstract void onRun(); |
| 147 } | 149 } |
| OLD | NEW |