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

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

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

Powered by Google App Engine
This is Rietveld 408576698