Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: utils/pub/pub.dart

Issue 10340005: Add support for pub install. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix Chromium review errors? Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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('cache.dart'); 15 #source('system_cache.dart');
16 #source('app_cache.dart');
16 #source('command_list.dart'); 17 #source('command_list.dart');
18 #source('command_install.dart');
17 #source('command_update.dart'); 19 #source('command_update.dart');
18 #source('command_version.dart'); 20 #source('command_version.dart');
19 #source('package.dart'); 21 #source('package.dart');
22 #source('source.dart');
23 #source('sdk_source.dart');
20 24
21 main() { 25 main() {
22 final args = new Options().arguments; 26 final args = new Options().arguments;
23 27
24 // TODO(rnystrom): In addition to explicit "help" and "version" commands, 28 // TODO(rnystrom): In addition to explicit "help" and "version" commands,
25 // 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
26 // be consistent with other Unix apps. 30 // be consistent with other Unix apps.
27 final commands = { 31 final commands = {
28 'list': new ListCommand(), 32 'list': new ListCommand(),
33 'install': new InstallCommand(),
29 'update': new UpdateCommand(), 34 'update': new UpdateCommand(),
30 'version': new VersionCommand() 35 'version': new VersionCommand()
31 }; 36 };
32 37
33 if (args.length == 0) { 38 if (args.length == 0) {
34 printUsage(commands); 39 printUsage(commands);
35 return; 40 return;
36 } 41 }
37 42
38 // For consistency with expected unix idioms, support --help, -h, and 43 // For consistency with expected unix idioms, support --help, -h, and
39 // --version in addition to the regular commands. 44 // --version in addition to the regular commands.
40 if (args.length == 1) { 45 if (args.length == 1) {
41 if (args[0] == '--help' || args[0] == '-h') { 46 if (args[0] == '--help' || args[0] == '-h') {
42 printUsage(commands); 47 printUsage(commands);
43 return; 48 return;
44 } 49 }
45 50
46 if (args[0] == '--version') { 51 if (args[0] == '--version') {
47 printVersion(); 52 printVersion();
48 return; 53 return;
49 } 54 }
50 } 55 }
51 56
52 // TODO(rnystrom): Hack. This is temporary code to allow the pub tests to 57 // TODO(rnystrom): Hack. This is temporary code to allow the pub tests to
53 // pass in relevant paths. Eventually these should be either environment 58 // pass in relevant paths. Eventually these should be either environment
54 // variables or at least a cleaner arg parser. 59 // variables or at least a cleaner arg parser.
55 var cacheDir; 60 var cacheDir, sdkDir;
56 for (var i = 0; i < args.length; i++) { 61 for (var i = 0; i < args.length; i++) {
57 if (args[i].startsWith('--cachedir=')) { 62 if (args[i].startsWith('--cachedir=')) {
58 cacheDir = args[i].substring('--cachedir='.length); 63 cacheDir = args[i].substring('--cachedir='.length);
59 args.removeRange(i, 1); 64 args.removeRange(i, 1);
60 break; 65 i--;
66 } else if (args[i].startsWith('--sdkdir=')) {
67 sdkDir = args[i].substring('--sdkdir='.length);
68 args.removeRange(i, 1);
69 i--;
61 } 70 }
62 } 71 }
63 72
64 // TODO(rnystrom): Do we want this to be global? 73 // TODO(rnystrom): Do we want this to be global?
65 final cache = new PackageCache(cacheDir); 74 final systemCache = new SystemCache(cacheDir);
75
76 Source.defaultSource = new SdkSource(sdkDir);
66 77
67 // Select the command. 78 // Select the command.
68 final command = commands[args[0]]; 79 final command = commands[args[0]];
69 if (command == null) { 80 if (command == null) {
70 print('Unknown command "${args[0]}".'); 81 print('Unknown command "${args[0]}".');
71 print('Run "pub help" to see available commands.'); 82 print('Run "pub help" to see available commands.');
72 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.
73 return; 84 return;
74 } 85 }
75 86
76 args.removeRange(0, 1); 87 args.removeRange(0, 1);
77 command.run(cache, args); 88 command.run(systemCache, args);
78 } 89 }
79 90
80 /** Displays usage information for the app. */ 91 /** Displays usage information for the app. */
81 void printUsage(Map<String, PubCommand> commands) { 92 void printUsage(Map<String, PubCommand> commands) {
82 print('Pub is a package manager for Dart.'); 93 print('Pub is a package manager for Dart.');
83 print(''); 94 print('');
84 print('Usage:'); 95 print('Usage:');
85 print(''); 96 print('');
86 print(' pub command [arguments]'); 97 print(' pub command [arguments]');
87 print(''); 98 print('');
(...skipping 28 matching lines...) Expand all
116 * finds the package that the user is currently "in". 127 * finds the package that the user is currently "in".
117 */ 128 */
118 Future<Package> getWorkingPackage() { 129 Future<Package> getWorkingPackage() {
119 // TODO(rnystrom): Will eventually need better logic to walk up 130 // TODO(rnystrom): Will eventually need better logic to walk up
120 // subdirectories until we hit one that looks package-like. For now, just 131 // subdirectories until we hit one that looks package-like. For now, just
121 // assume the cwd is it. 132 // assume the cwd is it.
122 return Package.load(workingDir); 133 return Package.load(workingDir);
123 } 134 }
124 135
125 class PubCommand { 136 class PubCommand {
126 PackageCache cache; 137 SystemCache systemCache;
138 AppCache appCache;
127 139
128 abstract String get description(); 140 abstract String get description();
129 141
130 void run(PackageCache cache_, List<String> args) { 142 void run(SystemCache systemCache_, List<String> args) {
131 cache = cache_; 143 systemCache = systemCache_;
144 appCache = new AppCache(workingDir, systemCache);
132 145
133 // TODO(rnystrom): Each command should define the arguments it expects and 146 // TODO(rnystrom): Each command should define the arguments it expects and
134 // we can handle them generically here. 147 // we can handle them generically here.
135 148
136 onRun(); 149 onRun();
137 } 150 }
138 151
139 abstract void onRun(); 152 abstract void onRun();
140 } 153 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698