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

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

Issue 9950005: First check in for pub package manager. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Respond to review. 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 /**
6 * The main entrypoint for the pub command line application.
7 */
8 #library('pub');
9
10 #import('utils.dart');
11
12 List<String, PubCommand> commands;
13
14 main() {
15 final args = new Options().arguments;
16
17 // TODO(rnystrom): In addition to explicit "help" and "version" commands,
18 // should also add special-case support for --help and --version arguments to
19 // be consistent with other Unix apps.
20 commands = {
21 'version': new PubCommand('print Pub version', showVersion)
22 };
23
24 if (args.length == 0) {
25 showUsage();
26 return;
27 }
28
29 // Select the command.
30 final command = commands[args[0]];
31 if (command == null) {
32 print('Unknown command "${args[0]}".');
33 print('Run "pub help" to see available commands.');
34 exit(64); // see http://www.freebsd.org/cgi/man.cgi?query=sysexits.
kasperl 2012/04/11 07:17:03 see -> See
Bob Nystrom 2012/04/11 16:50:23 Done (in a forthcoming patch).
35 return;
36 }
37
38 args.removeRange(0, 1);
39 command.function(args);
40 }
41
42 /** Displays usage information for the app. */
43 void showUsage() {
44 print('Pub is a package manager for Dart.');
kasperl 2012/04/11 07:17:03 Wouldn't this be nicer in a multiline string const
Bob Nystrom 2012/04/11 16:50:23 I did that at first, but the problem is multiline
45 print('');
46 print('Usage:');
47 print('');
48 print(' pub command [arguments]');
49 print('');
50 print('The commands are:');
51 print('');
52
53 // Show the commands sorted.
54 // TODO(rnystrom): A sorted map would be nice.
55 int length = 0;
56 final names = <String>[];
57 for (final command in commands.getKeys()) {
58 length = Math.max(length, command.length);
59 names.add(command);
60 }
61
62 names.sort((a, b) => a.compareTo(b));
63
64 for (final name in names) {
65 print(' ${padRight(name, length)} ${commands[name].description}');
66 }
67
68 print('');
69 print('Use "pub help [command]" for more information about a command.');
70 }
71
72 /** Displays pub version information. */
73 void showVersion(List<String> args) {
74 // TODO(rnystrom): Store some place central.
75 print('Pub 0.0.0');
76 }
77
78 typedef void CommandFunction(List<String> args);
79
80 class PubCommand {
81 final String description;
82 final CommandFunction function;
83
84 PubCommand(this.description, this.function);
85 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698