4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Console\Command;
14 use Symfony\Component\Console\Helper\DescriptorHelper;
15 use Symfony\Component\Console\Input\InputArgument;
16 use Symfony\Component\Console\Input\InputOption;
17 use Symfony\Component\Console\Input\InputInterface;
18 use Symfony\Component\Console\Output\OutputInterface;
19 use Symfony\Component\Console\Input\InputDefinition;
22 * ListCommand displays the list of all available commands for the application.
24 * @author Fabien Potencier <fabien@symfony.com>
26 class ListCommand extends Command
31 protected function configure()
35 ->setDefinition($this->createDefinition())
36 ->setDescription('Lists commands')
38 The <info>%command.name%</info> command lists all commands:
40 <info>php %command.full_name%</info>
42 You can also display the commands for a specific namespace:
44 <info>php %command.full_name% test</info>
46 You can also output the information in other formats by using the <comment>--format</comment> option:
48 <info>php %command.full_name% --format=xml</info>
50 It's also possible to get raw list of commands (useful for embedding command runner):
52 <info>php %command.full_name% --raw</info>
61 public function getNativeDefinition()
63 return $this->createDefinition();
69 protected function execute(InputInterface $input, OutputInterface $output)
71 if ($input->getOption('xml')) {
72 @trigger_error('The --xml option was deprecated in version 2.7 and will be removed in version 3.0. Use the --format option instead.', E_USER_DEPRECATED);
74 $input->setOption('format', 'xml');
77 $helper = new DescriptorHelper();
78 $helper->describe($output, $this->getApplication(), array(
79 'format' => $input->getOption('format'),
80 'raw_text' => $input->getOption('raw'),
81 'namespace' => $input->getArgument('namespace'),
88 private function createDefinition()
90 return new InputDefinition(array(
91 new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'),
92 new InputOption('xml', null, InputOption::VALUE_NONE, 'To output list as XML'),
93 new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list'),
94 new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt'),