1b3e39e1ad3ec8dd1445ab217ae9780c83058e1f
[yaffs-website] / vendor / drupal / console-core / src / Command / ListCommand.php
1 <?php
2 /**
3  * @file
4  * Contains \Drupal\Console\Core\Command\ListCommand.
5  */
6 namespace Drupal\Console\Core\Command;
7
8 use Symfony\Component\Console\Input\InputArgument;
9 use Symfony\Component\Console\Input\InputInterface;
10 use Symfony\Component\Console\Input\InputDefinition;
11 use Symfony\Component\Console\Input\InputOption;
12 use Drupal\Console\Core\Helper\DescriptorHelper;
13 use Symfony\Component\Console\Output\OutputInterface;
14
15 /**
16  * Class ListCommand
17  *
18  * @package Drupal\Console\Core\Command
19  */
20 class ListCommand extends Command
21 {
22     /**
23      * {@inheritdoc}
24      */
25     protected function configure()
26     {
27         $this
28             ->setName('list')
29             ->setDefinition($this->createDefinition())
30             ->setDescription($this->trans('commands.list.description'))
31             ->setHelp($this->trans('commands.list.help'));
32     }
33
34     /**
35      * {@inheritdoc}
36      */
37     public function getNativeDefinition()
38     {
39         return $this->createDefinition();
40     }
41
42     /**
43      * {@inheritdoc}
44      */
45     protected function execute(InputInterface $input, OutputInterface $output)
46     {
47         if ($input->getOption('xml')) {
48             $this->getIo()->info(
49                 'The --xml option was deprecated in version 2.7 and will be removed in version 3.0. Use the --format option instead',
50                 E_USER_DEPRECATED
51             );
52             $input->setOption('format', 'xml');
53         }
54         $commandName = $input->getFirstArgument()?$input->getFirstArgument():'help';
55         $helper = new DescriptorHelper();
56         $helper->describe(
57             $this->getIo(),
58             $this->getApplication(),
59             [
60                 'format' => $input->getOption('format'),
61                 'raw_text' => $input->getOption('raw'),
62                 'namespace' => $input->getArgument('namespace'),
63                 'translator' => $this->getApplication()->getTranslator(),
64                 'command' => $this->getApplication()->find($commandName)
65             ]
66         );
67
68         $this->getIo()->newLine();
69     }
70
71     /**
72      * {@inheritdoc}
73      */
74     private function createDefinition()
75     {
76         return new InputDefinition(
77             [
78                 new InputArgument('namespace', InputArgument::OPTIONAL, $this->trans('commands.list.arguments.namespace')),
79                 new InputOption('xml', null, InputOption::VALUE_NONE, $this->trans('commands.list.options.xml')),
80                 new InputOption('raw', null, InputOption::VALUE_NONE, $this->trans('commands.list.options.raw')),
81                 new InputOption('format', null, InputOption::VALUE_REQUIRED, $this->trans('commands.list.options.format'), 'txt'),
82             ]
83         );
84     }
85 }