Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / drush / drush / src / Commands / help / HelpCommands.php
1 <?php
2 namespace Drush\Commands\help;
3
4 use Consolidation\AnnotatedCommand\AnnotatedCommand;
5 use Consolidation\AnnotatedCommand\CommandData;
6 use Drush\Commands\DrushCommands;
7 use Drush\Drush;
8
9 class HelpCommands extends DrushCommands
10 {
11
12     /**
13      * Display usage details for a command.
14      *
15      * @command help
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.
25      * @bootstrap max
26      * @topics docs:readme
27      *
28      * @return \Consolidation\AnnotatedCommand\Help\HelpDocument
29      */
30     public function help($command_name = '', $options = ['format' => 'helpcli', 'include-field-labels' => false, 'table-style' => 'compact'])
31     {
32         $application = Drush::getApplication();
33         $command = $application->get($command_name);
34         if ($command instanceof AnnotatedCommand) {
35             $command->optionsHook();
36         }
37         $helpDocument = new DrushHelpDocument($command);
38
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);
43
44         return $helpDocument;
45     }
46
47     /**
48      * @hook validate help
49      */
50     public function validate(CommandData $commandData)
51     {
52         $name = $commandData->input()->getArgument('command_name');
53         if (empty($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."));
55         } else {
56             $application = Drush::getApplication();
57             if (!in_array($name, array_keys($application->all()))) {
58                 throw new \Exception(dt("!name command not found.", ['!name' => $name]));
59             }
60         }
61     }
62 }