| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library pub.command.help; | 5 library args.help_command; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import '../command_runner.dart'; |
| 8 | 8 |
| 9 import '../command.dart'; | 9 /// The built-in help command that's added to every [CommandRunner]. |
| 10 /// |
| 11 /// This command displays help information for the various subcommands. |
| 12 class HelpCommand extends Command { |
| 13 final name = "help"; |
| 14 String get description => |
| 15 "Display help information for ${runner.executableName}."; |
| 16 String get usage => "${runner.executableName} help [command]"; |
| 10 | 17 |
| 11 /// Handles the `help` pub command. | 18 void run() { |
| 12 class HelpCommand extends PubCommand { | |
| 13 String get description => "Display help information for Pub."; | |
| 14 String get usage => "pub help [command]"; | |
| 15 bool get takesArguments => true; | |
| 16 | |
| 17 Future onRun() { | |
| 18 // Show the default help if no command was specified. | 19 // Show the default help if no command was specified. |
| 19 if (commandOptions.rest.isEmpty) { | 20 if (options.rest.isEmpty) { |
| 20 PubCommand.printGlobalUsage(); | 21 runner.printUsage(); |
| 21 return null; | 22 return; |
| 22 } | 23 } |
| 23 | 24 |
| 24 // Walk the command tree to show help for the selected command or | 25 // Walk the command tree to show help for the selected command or |
| 25 // subcommand. | 26 // subcommand. |
| 26 var commands = PubCommand.mainCommands; | 27 var commands = runner.topLevelCommands; |
| 27 var command = null; | 28 var command = null; |
| 28 var commandString = "pub"; | 29 var commandString = runner.executableName; |
| 29 | 30 |
| 30 for (var name in commandOptions.rest) { | 31 for (var name in options.rest) { |
| 31 if (commands.isEmpty) { | 32 if (commands.isEmpty) { |
| 32 command.usageError( | 33 command.usageError( |
| 33 'Command "$commandString" does not expect a subcommand.'); | 34 'Command "$commandString" does not expect a subcommand.'); |
| 34 } | 35 } |
| 35 | 36 |
| 36 if (commands[name] == null) { | 37 if (commands[name] == null) { |
| 37 if (command == null) { | 38 if (command == null) { |
| 38 PubCommand.usageErrorWithCommands( | 39 runner.usageError('Could not find a command named "$name".'); |
| 39 commands, | |
| 40 'Could not find a command named "$name".'); | |
| 41 } | 40 } |
| 42 | 41 |
| 43 command.usageError( | 42 command.usageError( |
| 44 'Could not find a subcommand named "$name" for "$commandString".'); | 43 'Could not find a subcommand named "$name" for "$commandString".'); |
| 45 } | 44 } |
| 46 | 45 |
| 47 command = commands[name]; | 46 command = commands[name]; |
| 48 commands = command.subcommands; | 47 commands = command.subcommands; |
| 49 commandString += " $name"; | 48 commandString += " $name"; |
| 50 } | 49 } |
| 51 | 50 |
| 52 command.printUsage(); | 51 command.printUsage(); |
| 53 return null; | |
| 54 } | 52 } |
| 55 } | 53 } |
| OLD | NEW |