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

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: 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..f9e645d0f72b6ccb590342792b46d6453f831c03
--- /dev/null
+++ b/utils/pub/pub.dart
@@ -0,0 +1,79 @@
+// 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<PubCommand> commands;
nweiz 2012/03/30 00:38:37 This should probably be a hash.
Bob Nystrom 2012/03/30 01:06:17 Done.
+
+main() {
+ final args = new Options().arguments;
+
+ commands = [
+ new PubCommand('version', 'print Pub version', showVersion)
nweiz 2012/03/30 00:38:37 Not something worth changing in this CL, but at so
Bob Nystrom 2012/03/30 01:06:17 Good call. Added a TODO.
+ ];
+
+ if (args.length == 0) {
+ showUsage();
+ return;
+ }
+
+ // Select the command.
+ final commandName = args[0];
+ args.removeRange(0, 1);
+
+ for (final command in commands) {
+ if (command.name == commandName) {
+ command.function(args);
+ return;
+ }
+ }
+
+ // If we got here, the command wasn't recognized.
+ print('Unknown command "$commandName".');
+ print('Run "pub help" to see available commands.');
+ exit(64); // EX_USAGE, see http://www.freebsd.org/cgi/man.cgi?query=sysexits.
+}
+
+/** Displays usage information for the app. */
+void showUsage() {
+ print('Pub is a package manager for Dart.');
+ print('');
+ print('Usage:');
+ print('');
+ print(' pub command [arguments]');
+ print('');
+ print('The commands are:');
+ print('');
+
+ int length = 0;
+ commands.forEach((command) => length = Math.max(length, command.name.length));
+
+ for (final command in commands) {
+ print(' ${padRight(command.name, length)} ${command.description}');
nweiz 2012/03/30 00:38:37 I'm not sure two spaces between the command name a
Bob Nystrom 2012/03/30 01:06:17 Done.
+ }
+
+ 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 name;
+ final String description;
+ final CommandFunction function;
+
+ PubCommand(this.name, this.description, this.function);
+}

Powered by Google App Engine
This is Rietveld 408576698