883c3d42ba4b0281a8073cf746497ecd77fd7183
[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 use Symfony\Component\Console\Command\Command;
15 use Drupal\Console\Core\Command\Shared\CommandTrait;
16 use Drupal\Console\Core\Style\DrupalStyle;
17
18 /**
19  * Class ListCommand
20  *
21  * @package Drupal\Console\Core\Command
22  */
23 class ListCommand extends Command
24 {
25     use CommandTrait;
26
27     /**
28      * {@inheritdoc}
29      */
30     protected function configure()
31     {
32         $this
33             ->setName('list')
34             ->setDefinition($this->createDefinition())
35             ->setDescription($this->trans('commands.list.description'))
36             ->setHelp($this->trans('commands.list.help'));
37     }
38
39     /**
40      * {@inheritdoc}
41      */
42     public function getNativeDefinition()
43     {
44         return $this->createDefinition();
45     }
46
47     /**
48      * {@inheritdoc}
49      */
50     protected function execute(InputInterface $input, OutputInterface $output)
51     {
52         $io = new DrupalStyle($input, $output);
53
54         if ($input->getOption('xml')) {
55             $io->info(
56                 'The --xml option was deprecated in version 2.7 and will be removed in version 3.0. Use the --format option instead',
57                 E_USER_DEPRECATED
58             );
59             $input->setOption('format', 'xml');
60         }
61         $helper = new DescriptorHelper();
62         $helper->describe(
63             $io,
64             $this->getApplication(),
65             [
66                 'format' => $input->getOption('format'),
67                 'raw_text' => $input->getOption('raw'),
68                 'namespace' => $input->getArgument('namespace'),
69                 'translator' => $this->getApplication()->getTranslator()
70             ]
71         );
72     }
73
74     /**
75      * {@inheritdoc}
76      */
77     private function createDefinition()
78     {
79         return new InputDefinition(
80             [
81                 new InputArgument('namespace', InputArgument::OPTIONAL, $this->trans('commands.list.arguments.namespace')),
82                 new InputOption('xml', null, InputOption::VALUE_NONE, $this->trans('commands.list.options.xml')),
83                 new InputOption('raw', null, InputOption::VALUE_NONE, $this->trans('commands.list.options.raw')),
84                 new InputOption('format', null, InputOption::VALUE_REQUIRED, $this->trans('commands.list.options.format'), 'txt'),
85             ]
86         );
87     }
88 }