Chromium Code Reviews| 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); |
| +} |