Chromium Code Reviews| 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 cacheDir = args[i].substring('--cachedir='.length); | 65 cacheDir = args[i].substring('--cachedir='.length); |
| 64 args.removeRange(i, 1); | 66 args.removeRange(i, 1); |
| 65 i--; | 67 i--; |
| 66 } else if (args[i].startsWith('--sdkdir=')) { | 68 } else if (args[i].startsWith('--sdkdir=')) { |
| 67 sdkDir = args[i].substring('--sdkdir='.length); | 69 sdkDir = args[i].substring('--sdkdir='.length); |
| 68 args.removeRange(i, 1); | 70 args.removeRange(i, 1); |
| 69 i--; | 71 i--; |
| 70 } | 72 } |
| 71 } | 73 } |
| 72 | 74 |
| 73 // TODO(rnystrom): Do we want this to be global? | 75 // TODO(rnystrom): Do we want this to be global? |
|
Bob Nystrom
2012/05/08 17:01:49
If you don't mind, remove this TODO. I think we've
nweiz
2012/05/09 00:21:04
Done.
| |
| 74 final cache = new SystemCache(cacheDir); | 76 final cache = new SystemCache(cacheDir); |
| 75 | 77 cache.sources.register(new SdkSource(sdkDir)); |
| 76 Source.defaultSource = new SdkSource(sdkDir); | 78 cache.sources.register(new GitSource()); |
| 79 cache.sources.setDefault('sdk'); | |
| 77 | 80 |
| 78 // Select the command. | 81 // Select the command. |
| 79 final command = commands[args[0]]; | 82 final command = commands[args[0]]; |
| 80 if (command == null) { | 83 if (command == null) { |
| 81 print('Unknown command "${args[0]}".'); | 84 print('Unknown command "${args[0]}".'); |
| 82 print('Run "pub help" to see available commands.'); | 85 print('Run "pub help" to see available commands.'); |
| 83 exit(64); // See http://www.freebsd.org/cgi/man.cgi?query=sysexits. | 86 exit(64); // See http://www.freebsd.org/cgi/man.cgi?query=sysexits. |
| 84 return; | 87 return; |
| 85 } | 88 } |
| 86 | 89 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 | 133 |
| 131 void run(SystemCache cache_, List<String> args) { | 134 void run(SystemCache cache_, List<String> args) { |
| 132 cache = cache_; | 135 cache = cache_; |
| 133 | 136 |
| 134 // TODO(rnystrom): Each command should define the arguments it expects and | 137 // TODO(rnystrom): Each command should define the arguments it expects and |
| 135 // we can handle them generically here. | 138 // we can handle them generically here. |
| 136 | 139 |
| 137 // TODO(rnystrom): Will eventually need better logic to walk up | 140 // TODO(rnystrom): Will eventually need better logic to walk up |
| 138 // subdirectories until we hit one that looks package-like. For now, just | 141 // subdirectories until we hit one that looks package-like. For now, just |
| 139 // assume the cwd is it. | 142 // assume the cwd is it. |
| 140 Package.load(workingDir).then((pkg) { | 143 Package.load(workingDir, cache.sources).then((pkg) { |
| 141 packagesDir = new PackagesDir(pkg, cache); | 144 packagesDir = new PackagesDir(pkg, cache); |
| 142 onRun(); | 145 onRun(); |
| 143 }); | 146 }); |
| 144 } | 147 } |
| 145 | 148 |
| 146 abstract void onRun(); | 149 abstract void onRun(); |
| 147 } | 150 } |
| OLD | NEW |