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

Unified 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, 9 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 side-by-side diff with in-line comments
Download patch
Index: utils/pub/pub.dart
diff --git a/utils/pub/pub.dart b/utils/pub/pub.dart
new file mode 100644
index 0000000000000000000000000000000000000000..a3a5ff3bb42c8da2d69661c36ed1af086eb98a34
--- /dev/null
+++ b/utils/pub/pub.dart
@@ -0,0 +1,85 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+/**
+ * The main entrypoint for the pub command line application.
+ */
+#library('pub');
+
+#import('utils.dart');
+
+List<String, PubCommand> commands;
+
+main() {
+ final args = new Options().arguments;
+
+ // TODO(rnystrom): In addition to explicit "help" and "version" commands,
+ // should also add special-case support for --help and --version arguments to
+ // be consistent with other Unix apps.
+ commands = {
+ 'version': new PubCommand('print Pub version', showVersion)
+ };
+
+ if (args.length == 0) {
+ showUsage();
+ return;
+ }
+
+ // Select the command.
+ final command = commands[args[0]];
+ if (command == null) {
+ print('Unknown command "${args[0]}".');
+ print('Run "pub help" to see available commands.');
+ 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).
+ return;
+ }
+
+ args.removeRange(0, 1);
+ command.function(args);
+}
+
+/** Displays usage information for the app. */
+void showUsage() {
+ 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
+ print('');
+ print('Usage:');
+ print('');
+ print(' pub command [arguments]');
+ print('');
+ print('The commands are:');
+ print('');
+
+ // Show the commands sorted.
+ // TODO(rnystrom): A sorted map would be nice.
+ int length = 0;
+ final names = <String>[];
+ for (final command in commands.getKeys()) {
+ length = Math.max(length, command.length);
+ names.add(command);
+ }
+
+ names.sort((a, b) => a.compareTo(b));
+
+ for (final name in names) {
+ print(' ${padRight(name, length)} ${commands[name].description}');
+ }
+
+ print('');
+ print('Use "pub help [command]" for more information about a command.');
+}
+
+/** Displays pub version information. */
+void showVersion(List<String> args) {
+ // TODO(rnystrom): Store some place central.
+ print('Pub 0.0.0');
+}
+
+typedef void CommandFunction(List<String> args);
+
+class PubCommand {
+ final String description;
+ final CommandFunction function;
+
+ PubCommand(this.description, this.function);
+}

Powered by Google App Engine
This is Rietveld 408576698