| 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('io.dart'); | 10 #import('io.dart'); |
| 11 #import('utils.dart'); | 11 #import('utils.dart'); |
| 12 | 12 |
| 13 #source('cache.dart'); | 13 #source('cache.dart'); |
| 14 #source('command_list.dart'); | 14 #source('command_list.dart'); |
| 15 #source('command_update.dart'); | 15 #source('command_update.dart'); |
| 16 #source('package.dart'); | 16 #source('package.dart'); |
| 17 | 17 |
| 18 Map<String, PubCommand> commands; | 18 Map<String, PubCommand> commands; |
| 19 PackageCache cache; |
| 19 | 20 |
| 20 main() { | 21 main() { |
| 21 final args = new Options().arguments; | 22 final args = new Options().arguments; |
| 22 | 23 |
| 23 // TODO(rnystrom): In addition to explicit "help" and "version" commands, | 24 // TODO(rnystrom): In addition to explicit "help" and "version" commands, |
| 24 // should also add special-case support for --help and --version arguments to | 25 // should also add special-case support for --help and --version arguments to |
| 25 // be consistent with other Unix apps. | 26 // be consistent with other Unix apps. |
| 26 commands = { | 27 commands = { |
| 27 'list': new PubCommand('print the contents of repositories', commandList), | 28 'list': new PubCommand('print the contents of repositories', commandList), |
| 29 'update': new PubCommand("update a package's dependencies", commandUpdate), |
| 28 'version': new PubCommand('print Pub version', commandVersion) | 30 'version': new PubCommand('print Pub version', commandVersion) |
| 29 }; | 31 }; |
| 30 | 32 |
| 31 if (args.length == 0) { | 33 if (args.length == 0) { |
| 32 showUsage(); | 34 showUsage(); |
| 33 return; | 35 return; |
| 34 } | 36 } |
| 35 | 37 |
| 36 // TODO(rnystrom): Hack. This is temporary code to allow the pub tests to | 38 // TODO(rnystrom): Hack. This is temporary code to allow the pub tests to |
| 37 // pass in relevant paths. Eventually these should be either environment | 39 // pass in relevant paths. Eventually these should be either environment |
| 38 // variables or at least a cleaner arg parser. | 40 // variables or at least a cleaner arg parser. |
| 39 var cacheDir; | 41 var cacheDir; |
| 40 for (var i = 0; i < args.length; i++) { | 42 for (var i = 0; i < args.length; i++) { |
| 41 if (args[i].startsWith('--cachedir=')) { | 43 if (args[i].startsWith('--cachedir=')) { |
| 42 cacheDir = args[i].substring('--cachedir='.length); | 44 cacheDir = args[i].substring('--cachedir='.length); |
| 43 args.removeRange(i, 1); | 45 args.removeRange(i, 1); |
| 44 break; | 46 break; |
| 45 } | 47 } |
| 46 } | 48 } |
| 47 | 49 |
| 50 // TODO(rnystrom): Do we want this to be global? |
| 51 cache = new PackageCache(cacheDir); |
| 52 |
| 48 var options = new PubOptions(cacheDir); | 53 var options = new PubOptions(cacheDir); |
| 49 | 54 |
| 50 // Select the command. | 55 // Select the command. |
| 51 final command = commands[args[0]]; | 56 final command = commands[args[0]]; |
| 52 if (command == null) { | 57 if (command == null) { |
| 53 print('Unknown command "${args[0]}".'); | 58 print('Unknown command "${args[0]}".'); |
| 54 print('Run "pub help" to see available commands.'); | 59 print('Run "pub help" to see available commands.'); |
| 55 exit(64); // See http://www.freebsd.org/cgi/man.cgi?query=sysexits. | 60 exit(64); // See http://www.freebsd.org/cgi/man.cgi?query=sysexits. |
| 56 return; | 61 return; |
| 57 } | 62 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 print(''); | 94 print(''); |
| 90 print('Use "pub help [command]" for more information about a command.'); | 95 print('Use "pub help [command]" for more information about a command.'); |
| 91 } | 96 } |
| 92 | 97 |
| 93 /** Displays pub version information. */ | 98 /** Displays pub version information. */ |
| 94 void commandVersion(PubOptions options, List<String> args) { | 99 void commandVersion(PubOptions options, List<String> args) { |
| 95 // TODO(rnystrom): Store some place central. | 100 // TODO(rnystrom): Store some place central. |
| 96 print('Pub 0.0.0'); | 101 print('Pub 0.0.0'); |
| 97 } | 102 } |
| 98 | 103 |
| 104 /** |
| 105 * Gets the package that contains the current working directory. In other words, |
| 106 * finds the package that the user is currently "in". |
| 107 */ |
| 108 Future<Package> getWorkingPackage() { |
| 109 // TODO(rnystrom): Will eventually need better logic to walk up |
| 110 // subdirectories until we hit one that looks package-like. For now, just |
| 111 // assume the cwd is it. |
| 112 return Package.load(workingDir); |
| 113 } |
| 114 |
| 99 typedef void CommandFunction(PubOptions options, List<String> args); | 115 typedef void CommandFunction(PubOptions options, List<String> args); |
| 100 | 116 |
| 101 class PubCommand { | 117 class PubCommand { |
| 102 final String description; | 118 final String description; |
| 103 final CommandFunction function; | 119 final CommandFunction function; |
| 104 | 120 |
| 105 PubCommand(this.description, this.function); | 121 PubCommand(this.description, this.function); |
| 106 } | 122 } |
| 107 | 123 |
| 108 class PubOptions { | 124 class PubOptions { |
| 109 final String cacheDir; | 125 final String cacheDir; |
| 110 | 126 |
| 111 PubOptions(this.cacheDir); | 127 PubOptions(this.cacheDir); |
| 112 } | 128 } |
| OLD | NEW |