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