Index: sdk/lib/_internal/pub/bin/pub.dart |
diff --git a/sdk/lib/_internal/pub/bin/pub.dart b/sdk/lib/_internal/pub/bin/pub.dart |
index 451ee6cea3d451c75db7d2f6abf40b1ea12f98d9..777105ba1b0fcea6e3e1e1ed97345b8a184413d1 100644 |
--- a/sdk/lib/_internal/pub/bin/pub.dart |
+++ b/sdk/lib/_internal/pub/bin/pub.dart |
@@ -4,7 +4,6 @@ |
import 'dart:async'; |
import 'dart:io'; |
-import 'dart:math' as math; |
import 'package:args/args.dart'; |
import 'package:path/path.dart' as path; |
@@ -16,13 +15,11 @@ import '../lib/src/log.dart' as log; |
import '../lib/src/sdk.dart' as sdk; |
import '../lib/src/utils.dart'; |
-final pubArgParser = initArgParser(); |
- |
void main(List<String> arguments) { |
ArgResults options; |
try { |
- options = pubArgParser.parse(arguments); |
+ options = PubCommand.pubArgParser.parse(arguments); |
} on FormatException catch (e) { |
log.error(e.message); |
log.error('Run "pub help" to see available options.'); |
@@ -36,14 +33,14 @@ void main(List<String> arguments) { |
} |
if (options['help']) { |
- printUsage(); |
+ PubCommand.printGlobalUsage(); |
return; |
} |
if (options.command == null) { |
if (options.rest.isEmpty) { |
// No command was chosen. |
- printUsage(); |
+ PubCommand.printGlobalUsage(); |
} else { |
log.error('Could not find a command named "${options.rest[0]}".'); |
log.error('Run "pub help" to see available commands.'); |
@@ -88,36 +85,6 @@ void main(List<String> arguments) { |
}); |
} |
-ArgParser initArgParser() { |
- var argParser = new ArgParser(); |
- |
- // Add the global options. |
- argParser.addFlag('help', abbr: 'h', negatable: false, |
- help: 'Print this usage information.'); |
- argParser.addFlag('version', negatable: false, |
- help: 'Print pub version.'); |
- argParser.addFlag('trace', |
- help: 'Print debugging information when an error occurs.'); |
- argParser.addOption('verbosity', |
- help: 'Control output verbosity.', |
- allowed: ['normal', 'io', 'solver', 'all'], |
- allowedHelp: { |
- 'normal': 'Show errors, warnings, and user messages.', |
- 'io': 'Also show IO operations.', |
- 'solver': 'Show steps during version resolution.', |
- 'all': 'Show all output including internal tracing messages.' |
- }); |
- argParser.addFlag('verbose', abbr: 'v', negatable: false, |
- help: 'Shortcut for "--verbosity=all".'); |
- |
- // Register the commands. |
- PubCommand.commands.forEach((name, command) { |
- argParser.addCommand(name, command.commandParser); |
- }); |
- |
- return argParser; |
-} |
- |
/// Checks that pub is running on a supported platform. If it isn't, it prints |
/// an error message and exits. Completes when the validation is done. |
Future validatePlatform() { |
@@ -132,43 +99,3 @@ Future validatePlatform() { |
}); |
}); |
} |
- |
-/// Displays usage information for the app. |
-void printUsage([String description = 'Pub is a package manager for Dart.']) { |
- // Build up a buffer so it shows up as a single log entry. |
- var buffer = new StringBuffer(); |
- buffer.write(description); |
- buffer.write('\n\n'); |
- buffer.write('Usage: pub command [arguments]\n\n'); |
- buffer.write('Global options:\n'); |
- buffer.write('${pubArgParser.getUsage()}\n\n'); |
- |
- // Show the commands sorted. |
- buffer.write('Available commands:\n'); |
- |
- // TODO(rnystrom): A sorted map would be nice. |
- int length = 0; |
- var names = <String>[]; |
- for (var command in PubCommand.commands.keys) { |
- // Hide aliases. |
- if (PubCommand.commands[command].aliases.indexOf(command) >= 0) continue; |
- |
- // Hide undocumented commands. |
- if (PubCommand.commands[command].hidden) continue; |
- |
- length = math.max(length, command.length); |
- names.add(command); |
- } |
- |
- names.sort((a, b) => a.compareTo(b)); |
- |
- for (var name in names) { |
- buffer.write(' ${padRight(name, length)} ' |
- '${PubCommand.commands[name].description}\n'); |
- } |
- |
- buffer.write('\n'); |
- buffer.write( |
- 'Use "pub help [command]" for more information about a command.'); |
- log.message(buffer.toString()); |
-} |