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

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

Issue 10091014: Start implementing pub object model. Rudimentary package cache class, and a simple pub command to l… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Platform is static now. Created 8 years, 8 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
« no previous file with comments | « utils/pub/package.dart ('k') | utils/tests/pub/pub_tests.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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('io.dart');
10 #import('utils.dart'); 11 #import('utils.dart');
11 12
12 List<String, PubCommand> commands; 13 #source('cache.dart');
14 #source('command_list.dart');
15 #source('command_update.dart');
16 #source('package.dart');
17
18 Map<String, PubCommand> commands;
13 19
14 main() { 20 main() {
15 final args = new Options().arguments; 21 final args = new Options().arguments;
16 22
17 // TODO(rnystrom): In addition to explicit "help" and "version" commands, 23 // TODO(rnystrom): In addition to explicit "help" and "version" commands,
18 // should also add special-case support for --help and --version arguments to 24 // should also add special-case support for --help and --version arguments to
19 // be consistent with other Unix apps. 25 // be consistent with other Unix apps.
20 commands = { 26 commands = {
21 'version': new PubCommand('print Pub version', showVersion) 27 'list': new PubCommand('print the contents of repositories', commandList),
28 'version': new PubCommand('print Pub version', commandVersion)
22 }; 29 };
23 30
24 if (args.length == 0) { 31 if (args.length == 0) {
25 showUsage(); 32 showUsage();
26 return; 33 return;
27 } 34 }
28 35
36 // TODO(rnystrom): Hack. This is temporary code to allow the pub tests to
37 // pass in relevant paths. Eventually these should be either environment
38 // variables or at least a cleaner arg parser.
39 var cacheDir;
40 for (var i = 0; i < args.length; i++) {
41 if (args[i].startsWith('--cachedir=')) {
42 cacheDir = args[i].substring('--cachedir='.length);
43 args.removeRange(i, 1);
44 break;
45 }
46 }
47
48 var options = new PubOptions(cacheDir);
49
29 // Select the command. 50 // Select the command.
30 final command = commands[args[0]]; 51 final command = commands[args[0]];
31 if (command == null) { 52 if (command == null) {
32 print('Unknown command "${args[0]}".'); 53 print('Unknown command "${args[0]}".');
33 print('Run "pub help" to see available commands.'); 54 print('Run "pub help" to see available commands.');
34 exit(64); // see http://www.freebsd.org/cgi/man.cgi?query=sysexits. 55 exit(64); // See http://www.freebsd.org/cgi/man.cgi?query=sysexits.
35 return; 56 return;
36 } 57 }
37 58
38 args.removeRange(0, 1); 59 args.removeRange(0, 1);
39 command.function(args); 60 command.function(options, args);
40 } 61 }
41 62
42 /** Displays usage information for the app. */ 63 /** Displays usage information for the app. */
43 void showUsage() { 64 void showUsage() {
44 print('Pub is a package manager for Dart.'); 65 print('Pub is a package manager for Dart.');
45 print(''); 66 print('');
46 print('Usage:'); 67 print('Usage:');
47 print(''); 68 print('');
48 print(' pub command [arguments]'); 69 print(' pub command [arguments]');
49 print(''); 70 print('');
(...skipping 13 matching lines...) Expand all
63 84
64 for (final name in names) { 85 for (final name in names) {
65 print(' ${padRight(name, length)} ${commands[name].description}'); 86 print(' ${padRight(name, length)} ${commands[name].description}');
66 } 87 }
67 88
68 print(''); 89 print('');
69 print('Use "pub help [command]" for more information about a command.'); 90 print('Use "pub help [command]" for more information about a command.');
70 } 91 }
71 92
72 /** Displays pub version information. */ 93 /** Displays pub version information. */
73 void showVersion(List<String> args) { 94 void commandVersion(PubOptions options, List<String> args) {
74 // TODO(rnystrom): Store some place central. 95 // TODO(rnystrom): Store some place central.
75 print('Pub 0.0.0'); 96 print('Pub 0.0.0');
76 } 97 }
77 98
78 typedef void CommandFunction(List<String> args); 99 typedef void CommandFunction(PubOptions options, List<String> args);
79 100
80 class PubCommand { 101 class PubCommand {
81 final String description; 102 final String description;
82 final CommandFunction function; 103 final CommandFunction function;
83 104
84 PubCommand(this.description, this.function); 105 PubCommand(this.description, this.function);
85 } 106 }
107
108 class PubOptions {
109 final String cacheDir;
110
111 PubOptions(this.cacheDir);
112 }
OLDNEW
« no previous file with comments | « utils/pub/package.dart ('k') | utils/tests/pub/pub_tests.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698