Chromium Code Reviews| Index: utils/pub/pub.dart |
| diff --git a/utils/pub/pub.dart b/utils/pub/pub.dart |
| index 9bb12ee39ae268de0dd126c1d1ad6a48f755dee9..df609ffec393f07a35feffc184a6a9bce2f277ac 100644 |
| --- a/utils/pub/pub.dart |
| +++ b/utils/pub/pub.dart |
| @@ -20,6 +20,7 @@ import 'entrypoint.dart'; |
| import 'exit_codes.dart' as exit_codes; |
| import 'git_source.dart'; |
| import 'hosted_source.dart'; |
| +import 'log.dart' as log; |
| import 'package.dart'; |
| import 'pubspec.dart'; |
| import 'sdk_source.dart'; |
| @@ -57,10 +58,21 @@ Map<String, PubCommand> get pubCommands { |
| ArgParser get pubArgParser { |
| var parser = new ArgParser(); |
| parser.addFlag('help', abbr: 'h', negatable: false, |
| - help: 'Prints this usage information'); |
| + help: 'print this usage information'); |
| parser.addFlag('version', negatable: false, |
| - help: 'Prints the version of Pub'); |
| - parser.addFlag('trace', help: 'Prints a stack trace when an error occurs'); |
| + help: 'print the version of pub'); |
| + parser.addFlag('trace', |
| + help: 'print debugging information when an error occurs'); |
| + parser.addOption('verbosity', |
| + help: 'control output verbosity', |
| + allowed: ['normal', 'info', 'debug', 'all'], |
|
nweiz
2012/12/05 23:56:54
"info" -> "io"
Bob Nystrom
2012/12/06 01:33:26
Done.
|
| + allowedHelp: { |
| + 'normal': 'errors, warnings, and user messages are shown', |
| + 'io': 'IO operations are also shown', |
| + 'all': 'all output including internal tracing messages are shown' |
| + }); |
| + parser.addFlag('verbose', abbr: 'v', negatable: false, |
| + help: 'shortcut for "--verbosity=all"'); |
| return parser; |
| } |
| @@ -69,8 +81,8 @@ main() { |
| try { |
| globalOptions = pubArgParser.parse(new Options().arguments); |
| } on FormatException catch (e) { |
| - printError(e.message); |
| - printError('Run "pub help" to see available options.'); |
| + log.error(e.message); |
| + log.error('Run "pub help" to see available options.'); |
| exit(exit_codes.USAGE); |
| } |
| @@ -84,6 +96,24 @@ main() { |
| return; |
| } |
| + if (globalOptions['trace']) { |
| + log.recordTranscript(); |
| + } |
| + |
| + switch (globalOptions['verbosity']) { |
| + case 'normal': log.showNormal(); break; |
| + case 'io': log.showIO(); break; |
| + case 'all': log.showAll(); break; |
| + default: |
| + // No specific verbosity given, so check for the shortcut. |
| + if (globalOptions['verbose']) { |
| + log.showAll(); |
| + } else { |
| + log.showNormal(); |
| + } |
| + break; |
| + } |
| + |
| // TODO(nweiz): Have a fallback for this this out automatically once 1145 is |
| // fixed. |
| var sdkDir = Platform.environment['DART_SDK']; |
| @@ -106,8 +136,8 @@ main() { |
| // Select the command. |
| var command = pubCommands[globalOptions.rest[0]]; |
| if (command == null) { |
| - printError('Could not find a command named "${globalOptions.rest[0]}".'); |
| - printError('Run "pub help" to see available commands.'); |
| + log.error('Could not find a command named "${globalOptions.rest[0]}".'); |
| + log.error('Run "pub help" to see available commands.'); |
| exit(exit_codes.USAGE); |
| return; |
| } |
| @@ -119,16 +149,16 @@ main() { |
| /** Displays usage information for the app. */ |
| void printUsage([String description = 'Pub is a package manager for Dart.']) { |
| - print(description); |
| - print(''); |
| - print('Usage: pub command [arguments]'); |
| - print(''); |
| - print('Global options:'); |
| - print(pubArgParser.getUsage()); |
| - print(''); |
| + log.message(description); |
| + log.message(''); |
| + log.message('Usage: pub command [arguments]'); |
| + log.message(''); |
| + log.message('Global options:'); |
| + log.message(pubArgParser.getUsage()); |
| + log.message(''); |
| // Show the commands sorted. |
| - print('Available commands:'); |
| + log.message('Available commands:'); |
| // TODO(rnystrom): A sorted map would be nice. |
| int length = 0; |
| @@ -143,15 +173,16 @@ void printUsage([String description = 'Pub is a package manager for Dart.']) { |
| names.sort((a, b) => a.compareTo(b)); |
| for (var name in names) { |
| - print(' ${padRight(name, length)} ${pubCommands[name].description}'); |
| + log.message(' ${padRight(name, length)} ' |
| + '${pubCommands[name].description}'); |
| } |
| - print(''); |
| - print('Use "pub help [command]" for more information about a command.'); |
| + log.message(''); |
| + log.message('Use "pub help [command]" for more information about a command.'); |
| } |
| void printVersion() { |
| - print('Pub $pubVersion'); |
| + log.message('Pub $pubVersion'); |
| } |
| abstract class PubCommand { |
| @@ -194,8 +225,8 @@ abstract class PubCommand { |
| try { |
| commandOptions = commandParser.parse(commandArgs); |
| } on FormatException catch (e) { |
| - printError(e.message); |
| - printError('Use "pub help" for more information.'); |
| + log.error(e.message); |
| + log.error('Use "pub help" for more information.'); |
| exit(exit_codes.USAGE); |
| } |
| @@ -210,9 +241,10 @@ abstract class PubCommand { |
| message = message.substring("Exception: ".length); |
| } |
| - printError(message); |
| + log.error(message); |
| if (globalOptions['trace'] && trace != null) { |
| - printError(trace); |
| + log.error(trace); |
| + log.dumpTranscript(); |
| } |
| exit(_chooseExitCode(error)); |
| @@ -269,14 +301,14 @@ abstract class PubCommand { |
| /** Displays usage information for this command. */ |
| void printUsage([String description]) { |
| if (description == null) description = this.description; |
| - print(description); |
| - print(''); |
| - print('Usage: $usage'); |
| + log.message(description); |
| + log.message(''); |
| + log.message('Usage: $usage'); |
| var commandUsage = commandParser.getUsage(); |
| if (!commandUsage.isEmpty) { |
| - print(''); |
| - print(commandUsage); |
| + log.message(''); |
| + log.message(commandUsage); |
| } |
| } |