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

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: More review changes 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('packages_dir.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 cache = 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
(...skipping 28 matching lines...) Expand all
104 } 115 }
105 116
106 print(''); 117 print('');
107 print('Use "pub help [command]" for more information about a command.'); 118 print('Use "pub help [command]" for more information about a command.');
108 } 119 }
109 120
110 void printVersion() { 121 void printVersion() {
111 print('Pub 0.0.0'); 122 print('Pub 0.0.0');
112 } 123 }
113 124
114 /**
115 * Gets the package that contains the current working directory. In other words,
116 * finds the package that the user is currently "in".
117 */
118 Future<Package> getWorkingPackage() {
119 // TODO(rnystrom): Will eventually need better logic to walk up
120 // subdirectories until we hit one that looks package-like. For now, just
121 // assume the cwd is it.
122 return Package.load(workingDir);
123 }
124
125 class PubCommand { 125 class PubCommand {
126 PackageCache cache; 126 SystemCache cache;
127 PackagesDir packagesDir;
127 128
128 abstract String get description(); 129 abstract String get description();
129 130
130 void run(PackageCache cache_, List<String> args) { 131 void run(SystemCache cache_, List<String> args) {
131 cache = cache_; 132 cache = cache_;
132 133
133 // TODO(rnystrom): Each command should define the arguments it expects and 134 // TODO(rnystrom): Each command should define the arguments it expects and
134 // we can handle them generically here. 135 // we can handle them generically here.
135 136
136 onRun(); 137 // TODO(rnystrom): Will eventually need better logic to walk up
138 // subdirectories until we hit one that looks package-like. For now, just
139 // assume the cwd is it.
140 Package.load(workingDir).then((pkg) {
141 packagesDir = new PackagesDir(pkg, cache);
142 onRun();
143 });
137 } 144 }
138 145
139 abstract void onRun(); 146 abstract void onRun();
140 } 147 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698