2 namespace Drush\Commands\help;
4 use Consolidation\AnnotatedCommand\AnnotatedCommand;
5 use Consolidation\AnnotatedCommand\CommandData;
6 use Drush\Commands\DrushCommands;
9 class HelpCommands extends DrushCommands
13 * Display usage details for a command.
16 * @param $command_name A command name
17 * @usage drush help pm-uninstall
18 * Show help for a command.
19 * @usage drush help pmu
20 * Show help for a command using an alias.
21 * @usage drush help --format=xml
22 * Show all available commands in XML format.
23 * @usage drush help --format=json
24 * All available commands, in JSON format.
28 * @return \Consolidation\AnnotatedCommand\Help\HelpDocument
30 public function help($command_name = '', $options = ['format' => 'helpcli', 'include-field-labels' => false, 'table-style' => 'compact'])
32 $application = Drush::getApplication();
33 $command = $application->get($command_name);
34 if ($command instanceof AnnotatedCommand) {
35 $command->optionsHook();
37 $helpDocument = new DrushHelpDocument($command);
39 // This serves as example about how a command can add a custom Formatter.
40 $formatter = new HelpCLIFormatter();
41 $formatterManager = Drush::getContainer()->get('formatterManager');
42 $formatterManager->addFormatter('helpcli', $formatter);
50 public function validate(CommandData $commandData)
52 $name = $commandData->input()->getArgument('command_name');
54 throw new \Exception(dt("The help command requires that a command name be provided. Run `drush list` to see a list of available commands."));
56 $application = Drush::getApplication();
57 if (!in_array($name, array_keys($application->all()))) {
58 throw new \Exception(dt("!name command not found.", ['!name' => $name]));