Yaffs site version 1.1
[yaffs-website] / vendor / drupal / console-core / src / Command / HelpCommand.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Core\Command\HelpCommand.
6  */
7
8 namespace Drupal\Console\Core\Command;
9
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Input\InputOption;
12 use Symfony\Component\Console\Input\InputInterface;
13 use Symfony\Component\Console\Input\InputDefinition;
14 use Symfony\Component\Console\Output\OutputInterface;
15 use Symfony\Component\Console\Command\Command;
16 use Drupal\Console\Core\Command\Shared\CommandTrait;
17 use Drupal\Console\Core\Style\DrupalStyle;
18 use Drupal\Console\Core\Helper\DescriptorHelper;
19
20 /**
21  * HelpCommand displays the help for a given command.
22  *
23  * @author Fabien Potencier <fabien@symfony.com>
24  */
25 class HelpCommand extends Command
26 {
27     use CommandTrait;
28
29     private $command;
30
31     /**
32      * {@inheritdoc}
33      */
34     protected function configure()
35     {
36         $this->ignoreValidationErrors();
37
38         $this
39             ->setName('help')
40             ->setDefinition($this->createDefinition())
41             ->setDescription($this->trans('commands.help.description'))
42             ->setHelp($this->trans('commands.help.help'));
43     }
44
45     /**
46      * Sets the command.
47      *
48      * @param $command
49      *  The command to set
50      */
51     public function setCommand($command)
52     {
53         $this->command = $command;
54     }
55
56     /**
57      * {@inheritdoc}
58      */
59     protected function execute(InputInterface $input, OutputInterface $output)
60     {
61         $io = new DrupalStyle($input, $output);
62
63         if (null === $this->command) {
64             $this->command = $this->getApplication()->find($input->getArgument('command_name'));
65         }
66
67         if ($input->getOption('xml')) {
68             $io->info($this->trans('commands.help.messages.deprecated'), E_USER_DEPRECATED);
69             $input->setOption('format', 'xml');
70         }
71
72         $helper = new DescriptorHelper();
73         $helper->describe(
74             $io,
75             $this->command,
76             [
77                 'format' => $input->getOption('format'),
78                 'raw_text' => $input->getOption('raw'),
79                 'command_name' => $input->getArgument('command_name'),
80                 'translator' => $this->getApplication()->getTranslator()
81             ]
82         );
83
84         $this->command = null;
85     }
86
87     /**
88      * {@inheritdoc}
89      */
90     private function createDefinition()
91     {
92         return new InputDefinition(
93             [
94             new InputArgument('command_name', InputArgument::OPTIONAL, $this->trans('commands.help.arguments.command_name'), 'help'),
95             new InputOption('xml', null, InputOption::VALUE_NONE, $this->trans('commands.help.options.xml')),
96             new InputOption('raw', null, InputOption::VALUE_NONE, $this->trans('commands.help.options.raw')),
97             new InputOption('format', null, InputOption::VALUE_REQUIRED, $this->trans('commands.help.options.format'), 'txt'),
98             ]
99         );
100     }
101 }