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