| 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('io.dart'); |
| 11 #import('pubspec.dart'); |
| 12 #import('source.dart'); |
| 13 #import('utils.dart'); |
| 14 #import('version.dart'); |
| 11 | 15 |
| 12 #import('io.dart'); | |
| 13 #import('utils.dart'); | |
| 14 | |
| 15 #source('system_cache.dart'); | |
| 16 #source('packages_dir.dart'); | |
| 17 #source('command_list.dart'); | 16 #source('command_list.dart'); |
| 18 #source('command_install.dart'); | 17 #source('command_install.dart'); |
| 19 #source('command_update.dart'); | 18 #source('command_update.dart'); |
| 20 #source('command_version.dart'); | 19 #source('command_version.dart'); |
| 20 #source('entrypoint.dart'); |
| 21 #source('package.dart'); | 21 #source('package.dart'); |
| 22 #source('source.dart'); | 22 #source('system_cache.dart'); |
| 23 #source('source_registry.dart'); | 23 |
| 24 #source('sdk_source.dart'); | 24 Version get pubVersion() => new Version(0, 0, 0); |
| 25 #source('git_source.dart'); | |
| 26 | 25 |
| 27 main() { | 26 main() { |
| 28 final args = new Options().arguments; | 27 var args = new Options().arguments; |
| 29 | 28 |
| 30 // TODO(rnystrom): In addition to explicit "help" and "version" commands, | 29 // TODO(rnystrom): In addition to explicit "help" and "version" commands, |
| 31 // should also add special-case support for --help and --version arguments to | 30 // should also add special-case support for --help and --version arguments to |
| 32 // be consistent with other Unix apps. | 31 // be consistent with other Unix apps. |
| 33 final commands = { | 32 var commands = { |
| 34 'list': new ListCommand(), | 33 'list': new ListCommand(), |
| 35 'install': new InstallCommand(), | 34 'install': new InstallCommand(), |
| 36 'update': new UpdateCommand(), | 35 'update': new UpdateCommand(), |
| 37 'version': new VersionCommand() | 36 'version': new VersionCommand() |
| 38 }; | 37 }; |
| 39 | 38 |
| 40 // TODO(rnystrom): Hack. This is temporary code to allow the pub tests to | 39 // TODO(rnystrom): Hack. This is temporary code to allow the pub tests to |
| 41 // pass in relevant paths. Eventually these should be either environment | 40 // pass in relevant paths. Eventually these should be either environment |
| 42 // variables or at least a cleaner arg parser. | 41 // variables or at least a cleaner arg parser. |
| 43 var cacheDir, sdkDir; | 42 var cacheDir, sdkDir; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 65 printUsage(commands); | 64 printUsage(commands); |
| 66 return; | 65 return; |
| 67 } | 66 } |
| 68 | 67 |
| 69 if (args[0] == '--version') { | 68 if (args[0] == '--version') { |
| 70 printVersion(); | 69 printVersion(); |
| 71 return; | 70 return; |
| 72 } | 71 } |
| 73 } | 72 } |
| 74 | 73 |
| 75 final cache = new SystemCache(cacheDir); | 74 var cache = new SystemCache(cacheDir); |
| 76 cache.sources.register(new SdkSource(sdkDir)); | 75 cache.sources.register(new SdkSource(sdkDir)); |
| 77 cache.sources.register(new GitSource()); | 76 cache.sources.register(new GitSource()); |
| 78 cache.sources.setDefault('sdk'); | 77 cache.sources.setDefault('sdk'); |
| 79 | 78 |
| 80 // Select the command. | 79 // Select the command. |
| 81 final command = commands[args[0]]; | 80 var command = commands[args[0]]; |
| 82 if (command == null) { | 81 if (command == null) { |
| 83 print('Unknown command "${args[0]}".'); | 82 print('Unknown command "${args[0]}".'); |
| 84 print('Run "pub help" to see available commands.'); | 83 print('Run "pub help" to see available commands.'); |
| 85 exit(64); // See http://www.freebsd.org/cgi/man.cgi?query=sysexits. | 84 exit(64); // See http://www.freebsd.org/cgi/man.cgi?query=sysexits. |
| 86 return; | 85 return; |
| 87 } | 86 } |
| 88 | 87 |
| 89 args.removeRange(0, 1); | 88 args.removeRange(0, 1); |
| 90 command.run(cache, args); | 89 command.run(cache, args); |
| 91 } | 90 } |
| 92 | 91 |
| 93 /** Displays usage information for the app. */ | 92 /** Displays usage information for the app. */ |
| 94 void printUsage(Map<String, PubCommand> commands) { | 93 void printUsage(Map<String, PubCommand> commands) { |
| 95 print('Pub is a package manager for Dart.'); | 94 print('Pub is a package manager for Dart.'); |
| 96 print(''); | 95 print(''); |
| 97 print('Usage:'); | 96 print('Usage:'); |
| 98 print(''); | 97 print(''); |
| 99 print(' pub command [arguments]'); | 98 print(' pub command [arguments]'); |
| 100 print(''); | 99 print(''); |
| 101 print('The commands are:'); | 100 print('The commands are:'); |
| 102 print(''); | 101 print(''); |
| 103 | 102 |
| 104 // Show the commands sorted. | 103 // Show the commands sorted. |
| 105 // TODO(rnystrom): A sorted map would be nice. | 104 // TODO(rnystrom): A sorted map would be nice. |
| 106 int length = 0; | 105 int length = 0; |
| 107 final names = <String>[]; | 106 var names = <String>[]; |
| 108 for (final command in commands.getKeys()) { | 107 for (var command in commands.getKeys()) { |
| 109 length = Math.max(length, command.length); | 108 length = Math.max(length, command.length); |
| 110 names.add(command); | 109 names.add(command); |
| 111 } | 110 } |
| 112 | 111 |
| 113 names.sort((a, b) => a.compareTo(b)); | 112 names.sort((a, b) => a.compareTo(b)); |
| 114 | 113 |
| 115 for (final name in names) { | 114 for (var name in names) { |
| 116 print(' ${padRight(name, length)} ${commands[name].description}'); | 115 print(' ${padRight(name, length)} ${commands[name].description}'); |
| 117 } | 116 } |
| 118 | 117 |
| 119 print(''); | 118 print(''); |
| 120 print('Use "pub help [command]" for more information about a command.'); | 119 print('Use "pub help [command]" for more information about a command.'); |
| 121 } | 120 } |
| 122 | 121 |
| 123 void printVersion() { | 122 void printVersion() { |
| 124 print('Pub 0.0.0'); | 123 print('Pub $pubVersion'); |
| 125 } | 124 } |
| 126 | 125 |
| 127 class PubCommand { | 126 class PubCommand { |
| 128 SystemCache cache; | 127 SystemCache cache; |
| 129 PackagesDir packagesDir; | 128 |
| 129 Entrypoint entrypoint; |
| 130 | 130 |
| 131 abstract String get description(); | 131 abstract String get description(); |
| 132 | 132 |
| 133 void run(SystemCache cache_, List<String> args) { | 133 void run(SystemCache cache_, List<String> args) { |
| 134 cache = cache_; | 134 cache = cache_; |
| 135 | 135 |
| 136 // TODO(rnystrom): Each command should define the arguments it expects and | 136 // TODO(rnystrom): Each command should define the arguments it expects and |
| 137 // we can handle them generically here. | 137 // we can handle them generically here. |
| 138 | 138 |
| 139 // TODO(rnystrom): Will eventually need better logic to walk up | 139 // TODO(rnystrom): Will eventually need better logic to walk up |
| 140 // 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 |
| 141 // assume the cwd is it. | 141 // assume the cwd is it. |
| 142 Package.load(workingDir, cache.sources).then((pkg) { | 142 Package.load(workingDir, cache.sources).then((package) { |
| 143 packagesDir = new PackagesDir(pkg, cache); | 143 entrypoint = new Entrypoint(package, cache); |
| 144 onRun(); | 144 onRun(); |
| 145 }); | 145 }); |
| 146 } | 146 } |
| 147 | 147 |
| 148 abstract void onRun(); | 148 abstract void onRun(); |
| 149 } | 149 } |
| OLD | NEW |