Chromium Code Reviews| Index: sdk/lib/_internal/pub/lib/src/command/help.dart |
| diff --git a/sdk/lib/_internal/pub/lib/src/command/help.dart b/sdk/lib/_internal/pub/lib/src/command/help.dart |
| index 91181754d3420882f9a398b0e5007598b224929c..d4dec41c8b9f3cdfba9925c7f0af6fea5e53230f 100644 |
| --- a/sdk/lib/_internal/pub/lib/src/command/help.dart |
| +++ b/sdk/lib/_internal/pub/lib/src/command/help.dart |
| @@ -19,18 +19,47 @@ class HelpCommand extends PubCommand { |
| bool get takesArguments => true; |
| Future onRun() { |
| + // Show the default help if no command was specified. |
| if (commandOptions.rest.isEmpty) { |
| PubCommand.printGlobalUsage(); |
| - } else { |
| - var name = commandOptions.rest[0]; |
| - var command = PubCommand.commands[name]; |
| - if (command == null) { |
| - log.error('Could not find a command named "$name".'); |
| - log.error('Run "pub help" to see available commands.'); |
| - return flushThenExit(exit_codes.USAGE); |
| + return null; |
| + } |
| + |
| + // Walk the command tree to show help for the selected command or |
| + // subcommand. |
| + var commands = PubCommand.mainCommands; |
| + var command = null; |
| + var commandString = "pub"; |
| + |
| + _usageError(message) { |
|
nweiz
2014/01/31 21:42:06
You've defined this same function here and in pub.
Bob Nystrom
2014/02/01 01:49:32
OK, done. This triggered a cascade of changes. To
|
| + var buffer = new StringBuffer(); |
| + buffer.writeln(message); |
| + PubCommand.listCommands(commands, buffer, isSubcommand: command != null); |
| + log.error(buffer); |
| + return flushThenExit(exit_codes.USAGE); |
| + } |
| + |
| + for (var name in commandOptions.rest) { |
| + if (commands.isEmpty) { |
| + return _usageError( |
| + 'Command "$commandString" does not expect a subcommand.'); |
| } |
| - command.printUsage(); |
| + if (commands[name] == null) { |
| + if (command == null) { |
| + return _usageError('Could not find a command named "$name".'); |
|
nweiz
2014/01/31 21:42:06
Same issue with "find" as before.
Bob Nystrom
2014/02/01 01:49:32
Same explanation as before. :)
|
| + } |
| + |
| + return _usageError('Could not find a subcommand named "$name" ' |
| + 'for "$commandString".'); |
| + } |
| + |
| + command = commands[name]; |
| + commands = command.subcommands; |
| + commandString += " $name"; |
| } |
| + |
| + command.printUsage(); |
| + return null; |
| } |
| } |