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\Input\InputArgument;
15 use Symfony\Component\Console\Input\InputOption;
16 use Symfony\Component\Console\Input\InputInterface;
17 use Symfony\Component\Console\Output\OutputInterface;
18 use Symfony\Component\Console\Output\Output;
19 use Symfony\Component\Console\Command\Command;
20 use Symfony\Component\Console\Input\InputDefinition;
23 * ListCommand displays the list of all available commands for the application.
25 * @author Fabien Potencier <fabien@symfony.com>
27 class ListCommand extends Command
32 protected function configure()
36 ->setDefinition($this->createDefinition())
37 ->setDescription('Lists commands')
39 The <info>%command.name%</info> command lists all commands:
41 <info>php %command.full_name%</info>
43 You can also display the commands for a specific namespace:
45 <info>php %command.full_name% test</info>
47 You can also output the information as XML by using the <comment>--xml</comment> option:
49 <info>php %command.full_name% --xml</info>
51 It's also possible to get raw list of commands (useful for embedding command runner):
53 <info>php %command.full_name% --raw</info>
62 protected function getNativeDefinition()
64 return $this->createDefinition();
70 protected function execute(InputInterface $input, OutputInterface $output)
72 if ($input->getOption('xml')) {
73 $output->writeln($this->getApplication()->asXml($input->getArgument('namespace')), OutputInterface::OUTPUT_RAW);
75 $output->writeln($this->getApplication()->asText($input->getArgument('namespace'), $input->getOption('raw')));
79 private function createDefinition()
81 return new InputDefinition(array(
82 new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'),
83 new InputOption('xml', null, InputOption::VALUE_NONE, 'To output help as XML'),
84 new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list'),